Bug Vanquisher

24 April 2009

Tales From Interviewer’s Desk

Filed under: Dev inside!, Fun, Tips — Tanveer Badar @ 8:24 PM

Part 1:

How to reverse a string in-place?

Take 1: (Fresh)

string reverse( string str )
{
    char ch = str [ 0 ];
    foreach( int i = 0 ; i < str.length ; ++i )
        Response.RedirectWrite( str [ str.length – i ] ) + ch.tostring( );
}

Take 2: (Big words, no knowledge)

string reverse( object obj )
{
    string str = TypeCaste.tostring( obj );
    stack< ch > s;
    for( int i = 0 ; i < length ; ++i )
        s.push( str.charat( i ) );
    for( i = 0 ; i < length ; ++i )
        str.insertat( 0 , s.pop( ) );
}

Take 3: (2.5  year experience in C#)

string reverse( object obj )
{
    if( typeof( obj ) == "string" )
    {
        for( int i = 0 ; i < obj.length ; ++I )
        {
            char ch = str [ i ];
            str [ i ] = str [ length – i ];
            str [ length – i ] = ch;
        }
    }
    return obj.tostring( );
}

Take 4: (Fresh)

string reverse( object obj )
{
    if( obj == "string" )
    {
        char ch = str [ 0 ];
        for( int i = 0 ; i < obj.length ; ++I )
            str [ i ] = str [ length – i ];
        str [ str.length ] = ch;
    }
}

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: