C++ Coding Logic - Various Ideas

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sankaran1984
    New Member
    • Jul 2010
    • 2

    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:
    Code:
    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..
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You should be using string objects in C++ rather than C strings.

    Your comparison would be between a forward and a reverse iterator. That way you just increment both iterators in your loop.

    Comment

    Working...