First let me describe the program
All it does is pull in some chars and stores them in a linked list of stacks.
I have the code written to pull them in but when I need to print them I dont know how to go backwards without deleting the node.
This is how I created the nodes
void BigStack::Push(char ch)
{
MiniStack* stackPtr;
ListNode* nextPtr;
if (num == 0 || headPtr->stackPtr->IsFull())
{
ListNode* tempPtr = new ListNode;
tempPtr->nextPtr = headPtr;
headPtr = tempPtr;
tempPtr->stackPtr = new MiniStack;
tempPtr->stackPtr->Push(ch);
delete tempPtr;
}
else
headPtr->stackPtr->Push(ch);
num++;
}
And this is the function that is supposed to print the stack from top to bottom so that they print out in the LIFO fashon. The other program has a Print() function in it that has to be used.
This is what I have so far but I know it is not correct.
How would I do this?
void BigStack::Print() const // Prints stack contents, top to bottom
{
int n;
ListNode* printPtr;
ListNode* printPtr2;
for (n = num; n != -1; n--)
{
if (headPtr->stackPtr->IsEmpty() && nextPtr == NULL)
{
printPtr = headPtr;
printPtr->nextPtr = printPtr2;
}
}
}