C++ Coding Logic - Various Ideas

I want to write a method to determine if a given string is a palindrome. E.g. "Madam I'm Adam", or "A man, a plan, a canal, Panama".

The prototype for the function is:
bool is_palindrome(char const * str)

I have a simple logic to check for equality by moving forward & backward from extreme ends of the string.
But, i would like to know how many efficient ways to do this ? All ideas welcome from C++ gurus..
I'd be interested to see your algorithm for this. I would personally bung it into a std::string and use the STL algorithms to remove the spaces and punctuation and change the case before doing a reverse compare. But that's not necessarily very efficient.
You don't need <algorithm>, you can skip non-alphabetic characters while reading the string to compare the prefix and the suffix
What code have you written to implement this palindrome.
Fun trick to use, lowercase characters by and'ing the 6th bit, (char & 0x20) == lowercase(char), provided you know they are alpha characters.
you can use <cctype> functions instead...
Fun trick to use, lowercase characters by and'ing the 6th bit, (char & 0x20) == lowercase(char), provided you know they are alpha characters.

Even funnier is that this ain't gonna work ;)
You might mean bitwise OR instead of bitwise AND. You would not get a lot of a bitwise AND in this case.
Yea, sorry, mixed that up.
char & ~0x20 == uppercase
char | 0x20 == lowercase
Topic archived. No new replies allowed.