Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

palindrome probem

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi everyone, I'm a bu student in need of some help. I came in with no programming experience and I just got overloaded. Could you please help me make this palidrome fuction which states whether a certain string is a palindrome or not.

The fuction must have the prototype

bool palindrome(const char*)

I'm guessing you can use pointers to the addresses of the char in the array and then reaarange them in order of highest to lowest valued adress. Theen see if they're the same. Not sure. Please help!
 
Without giving away the answer by stating the code since this is a school problem, I see two solutions:

1)(low performance, high safety) Reverse the string and test for equality with the original. This is safe because I believe that C++ has built-in functions for both actions.
2)(high performance, low safety)
A) Place two pointers on the string, one at the beginning, one at the end.
B) Compare equality of the data.
C) Then increment the first one while decrementing the second one.
D) Repeat B and C until the latter pointer is in front of the first.

Hope this helps only...
Mike
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top