// Program to test whether an input line is a palindrome. Spaces, // punctuation, and the difference between upper- and lowercase are ignored. // This version uses stack2.h and queue2.h, rather than stack1.h and queue1.h. #include // Provides assert #include // Provides isalpha, toupper #include // Provides cout, cin, peek #include // Provides size_t, EXIT_SUCCESS #include "queue2.h" // Provides the Queue template class #include "stack2.h" // Provides the Stack template class void main( ) { Queue q; Stack s; char letter; // A character in the input string size_t mismatches = 0; // 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 >> letter; if (isalpha(letter)) { q.insert(toupper(letter)); s.push(toupper(letter)); } } while ((!q.is_empty( )) && (!s.is_empty( ))) { if (q.get_front( ) != s.pop( )) mismatches++; } if (mismatches == 0) cout << "That is a palindrome." << endl; else cout << "That is not a palindrome." << endl; }