Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

myronww

myronww myronww

Niner since 2004

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    Actually I think I could get away with performing one less iteration for odd length strings by changing

    while(lptr <= rptr);

    to

    while(lptr < rptr);

    because we would not need to look at the center character for odd length strings.
  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    //This does not handle white space but it should efficiently

    //look for a forward and reverse character pattern. like so "ab c ba"

    bool IsPalendrone(char* ptext)

    {

    bool rtnval = true;

    //Check for NULL or a zero length string

    if((ptext == NULL) || (*ptext == 0))

    return false;

    int textlen = strlen(ptext);

    //Check for the case where ptext is only on char

    if(textlen == 1)

    return rtnval;

    //ptext is more than one car we need to do some

    //comparisons

    char* lptr = ptext;

    char* rptr = ptext + (textlen - 1);

    do

    {

    //If we find a case where the character pointed to on

    //the left and right are not equal we can say this is

    //not a palendrone

    if((*lptr) != (*rptr))

    {

    rtnval = false;

    break;

    }

    //Move our pointer towards each other

    lptr++;

    rptr--;

    }while(lptr <= rptr);

    return rtnval;

    }