// main.cxx -- John Valois (valoisj@cs.rpi.edu)

// Simple project to test if a word is a palindrome (spelled the same 
// forward and backward) using a simple stack class.


#include <iostream>
#include <string>
#include "stack.h"

using std::cout;
using std::cin;
using std::endl;


int main()
{
  // Get the word to check.
  cout << "Enter a word: ";
  std::string word;
  cin >> word;
  
  // Push the characters onto a stack.
  stack<char> s(100);
  for (int i=0; i < word.size(); ++i)
    s.push(word[i]);

  // Pop characters from stack, comparing to corresponding character
  // in the original word.
  bool is_palindrome = true;
  int current_char = 0;
  while (!s.empty())
  {
    char c = s.top();
    s.pop();
    if (c != word[current_char++])
    {
      is_palindrome = false;
      break;
    }
  }

  // Output results.
  cout << "'" << word << "' is ";
  if (!is_palindrome)
    cout << "not ";
  cout << "a palindrome" << endl;
  return 0;
}

