What do Push and Pop mean for Stacks?

后端 未结 9 1101
臣服心动
臣服心动 2021-01-31 18:35

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 importan

9条回答
  •  遇见更好的自我
    2021-01-31 19:03

    A Stack is a LIFO (Last In First Out) data structure. The push and pop operations are simple. Push puts something on the stack, pop takes something off. You put onto the top, and take off the top, to preserve the LIFO order.

    edit -- corrected from FIFO, to LIFO. Facepalm!

    to illustrate, you start with a blank stack

    |

    then you push 'x'

    | 'x'

    then you push 'y'

    | 'x' 'y'

    then you pop

    | 'x'

提交回复
热议问题