Created
December 12, 2011 05:18
-
-
Save TheBuzzSaw/1465113 to your computer and use it in GitHub Desktop.
MyPalindrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool isPalindrome(const char* inText) | |
{ | |
if (!inText || !*inText) | |
return false; // Empty strings fail. OK? | |
const char* a = inText - 1; | |
const char* b = inText; | |
while (*++b); // Find the end of the string. | |
while (++a < --b) | |
{ | |
if (*a != *b) | |
return false; | |
} | |
return true; | |
} | |
void test(const char* inText) | |
{ | |
cout << "Testing word : " << inText << " : " | |
<< (isPalindrome(inText) ? "true" : "false") << endl; | |
} | |
int main(int argc, char** argv) | |
{ | |
test("hello"); | |
test("blargh"); | |
test("abba"); | |
test("10501"); | |
test("1001"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment