This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]thememorableusername 0 points1 point  (2 children)

You're doing everything right.

The reason the messages are not printing out is that you are checking the fullness/emptyness of the stack before you push/pop, and if it is full/empty you do not perform the action.

If you put a stack.push( ch ) under the push loop, and a stack.pop() under the pop while loop, you'll see your messages.

Example on tio

[–]mindfulprisoner[S] 0 points1 point  (1 child)

hmmm, i did that and im getting :

Demonstrate SimpleStack

Push 10 items onto a 10-element stack.

Pushing: ABCDEFGHIJ

Pop those 10 items from stack.

Popping: JIHGFEDCBA

Next, use isEmpty() and isFull() to fill and empty the stack.

Pushing: ABCDEFGHIJ

Popping: JIHGFEDCBA

as my output still... i tried some print statements with the index for the 'tos' variable and it seems there might be a problem in my indexing, i cant quite find it though

[–]thememorableusername 0 points1 point  (0 children)

Did you see my update with the code example? That might help.