//---------------------------------------------------------------------
// Provides a method to test whether a string is a palindrome.
// Non letters are skipped.
//---------------------------------------------------------------------
class BoundedStack
{
char* ptr;
public:
char top(void)
{
}
void push(char c)
{
}
void pop(void)
{
}
};
class BoundedQueue
{
char* ptr;
public:
void enqueue(char c)
{
}
char dequeue(void)
{
}
};
class Palindrome
{
public:
bool isLetter(char c)
{
}
char toLowerCase(char c)
{
}
bool testPalindrome(string candidate)
// Returns true if candidate is a palindrome, false otherwise.
{
char ch; // current candidate character being processed
int stringLength; // length of candidate string
int numLetters; // number of letter characters in candidate string
int charCount; // number of characters checked so far
char fromStack; // current character popped from stack
char fromQueue; // current character dequeued from queue
bool stillPalindrome; // true as long as the string might still be a palindrome
// initialize variables and structures
stringLength = candidate.length();
BoundedStack myStack(stringLength); // holds non blank string characters
BoundedQueue myQueue(stringLength); // also holds non blank string characters
numLetters = 0;
// obtain and handle characters
for (int i = 0; i < stringLength; i++)
{
ch = candidate[i];
if (isLetter(ch))
{
numLetters++;
ch = toLowerCase(ch);
myStack.push(ch);
myQueue.enqueue(ch);
}
}
// determine if palindrome
stillPalindrome = true;
charCount = 0;
while (stillPalindrome && (charCount < numLetters))
{
fromStack = myStack.top(); myStack.pop();
fromQueue = myQueue.dequeue();
if (fromStack != fromQueue)
stillPalindrome = false;
charCount++;
}
// return result
return stillPalindrome;
}
};
int main(){
Palindrome p;
string str;
getline(cin,str);
bool status = p.testPalindrome(str);
if(status) cout<<"The string: "<<str<<", is a Palindrome."<<endl;
else cout<<"The string: "<<str<<", is NOT a Palindrome."<<endl;
return 0;
}