// Program to test whether an input line is a palindrome. Spaces, // punctuation, and the difference between upper- and lowercase are ignored. #include // Provides assert #include // Provides isalpha, toupper #include // Provides cout, cin, peek #include // Provides size_t, EXIT_SUCCESS #include "queue1.h" // Provides the Queue template class #include "stack1.h" // Provides the Stack template class int main( ) { Queue q; Queue tq; Stack s; char letter; // A character in the input string int mismatchIndx = -1; // How often the queue does not match the stack cout << "Enter a line and I will see if it's a palindrome:" << endl; while (cin.peek( ) != '\n') { cin.get(letter); // cin >> letter; if (isalpha(letter) || letter == ' ') { assert(tq.size( ) < tq.CAPACITY); tq.insert(letter); assert(q.size( ) < q.CAPACITY); assert(s.size( ) < s.CAPACITY); q.insert(toupper(letter)); s.push(toupper(letter)); } } int i = -1; while ((!q.is_empty( )) && (!s.is_empty( ))) { i++; if (q.get_front( ) != s.pop( )) { mismatchIndx = i; break; } } if (mismatchIndx == -1) cout << "That is a palindrome." << endl; else { cout << "That is not a palindrome." << endl; cout << "Mismatch discovered at: "; for(int i=0; i <= mismatchIndx; i++) cout << tq.get_front(); } return EXIT_SUCCESS; }