The problem in the code is with your loop in void Stack::displayS() as it is iterating in the wrong direction. You start i from top and go as long as it is not less than 0, but in the iteration part, you do not decrease i's value (correct) but increase it instead (incorrect).
Your code correctly would be like this:
void displayS()
{
if (top == -1)
cout << "Stack underflow\n";
else
{
for (int i = top; i >= 0; i--)
cout << Sstore[i] << " ";
}
}
After this, your classes seem to work correctly.
I do not know what you need to do here, but here are some improvement opportunities:
- you have hardwired the size of your containers to be no more than SIZE. You don't need to do this. With the help of dynamic allocation, you can set the underlying array's size to any arbitrary number.
- with the help of generics, you can store any arbitrary type in your containers.