I am trying to build a program that can read a palindrome from a stack that i create... Below is my code that i have come up with some far but it seems that i am missing a few things. The current error i get is that constructers are not allowed a return type for the stack :: stack()... Also in my main (which i dont have yet) i am guessing that that is where i grab the string from the user? the cin?
Any help is welcomed!!
Thanks in advance!!
Code:
#include <iostream>
#include <string>
using namespace std;
class stack
{
public:
stack ();
stack(int n);
void push(char x);
void pop(char B);
bool isempty();
bool isfull();
private:
int TOP;
char * storage;
int size;
}
stack :: stack()
{
storage = new char[5];
TOP = -1;
}
bool stack :: isempty()
{
return TOP == -1;
}
stack :: stack (int n)
{
size = n;
storage = new char[n];
TOP = -1;
}
bool stack :: isfull()
{
return TOP == size -1;
}
void stack :: push(char x)
{
if (isfull())
cout<<"Stack is full"<<endl;
else
TOP++;
storage[TOP]=x;
}
void stack :: pop(char B)
{
if (isempty())
{
cout<<"Stack is empty"<<endl;
}
else
{
B = storage[TOP--];
}
}
