What do Push and Pop mean for Stacks?

adam shankman picture adam shankman · Sep 29, 2010 · Viewed 131.1k times · Source

long story short my lecturer is crap, and was showing us infix to prefix stacks via an overhead projector and his bigass shadow was blocking everything so i missed the important stuff

he was referring to push and pop, push = 0 pop = x

he gave an example but i cant see how he gets his answer at all,

2*3/(2-1)+5*(4-1)

step 1 Reverse : )1-4(*5+)1-2(/3*2 ok i can see that

he then went on writing x's and o's operations and i got totally lost

answer 14-5*12-32*/+ then reversed again to get +/*23-21*5-41

if some one could explain to me the push pop so i could understand i would be very greatful, i have looked online but alot stuff im finding seems to be a step above this, so i really need to get an understanding here first

Answer

Onion-Knight picture Onion-Knight · Sep 29, 2010

Hopefully this will help you visualize a Stack, and how it works.

Empty Stack:

|     |
|     |
|     |
-------

After Pushing A, you get:

|     |
|     |
|  A  |
-------

After Pushing B, you get:

|     |
|  B  |
|  A  |
-------

After Popping, you get:

|     |
|     |
|  A  |
-------

After Pushing C, you get:

|     |
|  C  |
|  A  |
-------

After Popping, you get:

|     |
|     |
|  A  |
-------

After Popping, you get:

|     |
|     |
|     |
-------