class Node
{
private:
int integer;
Node *pointer;
public:
Node(int x = 0, Node *y = NULL)
{
integer = x;
pointer = y;
}
int getInteger()
{
return integer;
}
Node getPointer()
{
return *pointer;
}
};
private:
Node *stack;
Node *top;
int listSize;
int pushedValue;
int pushCounter;
public:
Stack(int size)
{
top = NULL;
pushCounter = 0;
listSize = size;
}
//other code... ////
void push(int value)
{
if(pushCounter == listSize)
{
cout<<"\nOverflow"<<endl;
}
else
{
stack = new Node(value, top);
top = stack;
cout<<"\nYou just pushed the number "<<value<<"."<<endl;
pushCounter++;
printStack();
}
}
void printStack()
{
if(top = NULL)
{
cout<<"\nStack is empty"<<endl;
}
else
{
cout<<"\nYour stack is now:"<<endl;
for(Node *i = top; i != NULL; i->getPointer())
{
cout<<i->getInteger()<<endl;
}
}
}
So when I run it I can't seem to get it to print the stack... It tells me
"Your stack is now:"
and then nothing. It just continues the code. I'm thinking a possibility would be that I am not actually saving a value into the node?
Any help?