What do Push and Pop mean for Stacks?

后端 未结 9 1186
臣服心动
臣服心动 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:02

    A stack in principle is quite simple: imagine a rifle's clip - You can only access the topmost bullet - taking it out is called "pop", inserting a new one is called "push".
    A very useful example for that is for applications that allow you to "undo".
    Imagine you save each state of the application in a stack. e.g. the state of the application after every type the user makes.
    Now when the user presses "undo" you just "pop" the previous state from the stack. For every action the user does - you "push" the new state to the stack (that's of course simplified).
    About what your lecturer specifically was doing - in order to explain it some more information would be helpful..

提交回复
热议问题