I am writing a program to prove if a code is a Palindrome or not and must use stacks. I have written a code below that compiles, but when I run it, it outputs the word in an a stack view, but does not follow the rest of my program or does nothing else. Basically I think it is "popping" it but for some reason not "pushing" back in. Also, I don't think it is excluding spaces and case insensitive. Can anyone help?
Here is the code:
Thanks!
*****************************************************
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
class stack_type // Declaration of Class
{
public:
void clear_stack();
bool empty_stack();
bool full_stack();
void push(char word);
void pop(char& word);
int stack [200];
int top;
};
int main ()
{
stack_type s;
int i;
char word;
std::string test;
char phrase[200], new_phrase[200];
char response;
s.clear_stack();
cout <<"\nDisplay the top, after clearing the stack --> "<<s.top<<"\n";
i=0;
int z=0;
cout <<"\nEnter a word to see if it is a Palindrome!\n";
cin>> word;
cout<<word<<endl;
while (!(s.full_stack())&& word!='quit')
{
s.push(word);
phrase[i]=word;
i++;
cin>>word;
cout<<word<<"\n";
}
//end while
int j = 0;
while(!(s.empty_stack()))
{
s.pop(word);
new_phrase[j]=word;
j++;
}
//end while
for(int k=0; k<j; k++)
cout << phrase[k];
//end for
for (k=0; k<j; k++)
{
if (phrase[k]==new_phrase[k])
cout << word << " This word is a palindrome. \n";
else
cout << word << " This word is not a palindrome. \n";
}
cout << endl;
cout << "\nMore (Y or N)? ";
cin >> response;
while (response == 'Y' || response == 'y');
return 0;
}
//----------------------------------------------------------------------
void stack_type::clear_stack()
{
top = 0;
}
//----------------------------------------------------------------------
bool stack_type::empty_stack()
{
if (top==0)
return true;
else
return false;
}
//----------------------------------------------------------------------
bool stack_type::full_stack()
{
if (top==200)
return true;
else
return false;
}
//----------------------------------------------------------------------
void stack_type::push(char word)
{
top = top + 1;
stack[top]=word;
}
//----------------------------------------------------------------------
void stack_type::pop(char& word)
{
word = stack[top];
top = top - 1;
}