1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include "stack.h"
#include "queue.h"
#include <cctype>
using namespace std;
void RemovePunct(string text, string &result);
void RemoveSpaces(string text, string &result);
void toUpperCase(string s);
int main()
{
bool isPalindrome = false;
Stack<char> palindromeStack;
Queue<char> palindromeQueue;
string palindrome, palindromePunctDel, palindromeSpacesDel;
cout << "Welcome to the Palindrome Checker\nWhat would you like to check?\n";
getline(cin, palindrome);
RemovePunct(palindrome, palindromePunctDel);
RemoveSpaces(palindromePunctDel, palindromeSpacesDel);
toUpperCase(palindromeSpacesDel);
for (int x; x < palindromeSpacesDel.length(); x++)
{
palindromeStack.push(palindromeSpacesDel[x]);
palindromeQueue.enqueue(palindromeSpacesDel[x]);
}
while (!palindromeStack.isEmpty())
{
char x;
char y;
palindromeStack.getTop(x);
palindromeStack.pop();
palindromeQueue.getFront(y);
palindromeQueue.dequeue();
if (x == y) {
isPalindrome = true;
}
else
{
isPalindrome = false;
}
}
if (isPalindrome == true)
{
cout << palindrome << " is a palindrome"<< endl;
}
else
{
cout << palindrome << " is not a palindrome"<< endl;
}
return 0;
}
void toUpperCase(string s)
{
for (int i = 0; i < s.size(); ++i)
{
s[i] = toupper(s[i]);
}
}
void RemovePunct(string text, string &result)
{
remove_copy_if(text.begin(), text.end(),back_inserter(result), ptr_fun<int, int>(ispunct));
}
void RemoveSpaces(string text, string &result)
{
remove_copy_if(text.begin(), text.end(),back_inserter(result), ptr_fun<int, int>(isspace));
}
|