Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created December 12, 2011 05:18
Show Gist options
  • Save TheBuzzSaw/1465113 to your computer and use it in GitHub Desktop.
Save TheBuzzSaw/1465113 to your computer and use it in GitHub Desktop.
MyPalindrome
#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