课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

What is a stack?

What is a stack?

- [Instructor] The stack data structure can be useful for algorithms where you need to keep track of state. A stack is an ordered series of objects, just like a list, but like a queue, the way we access, add, and remove items is a little different. When we work with the stack, we push objects on the top of the stack and pop objects off the stack. Items are added and removed from the same end. We add to the top and remove from the top. We say stacks follow a last-in, first-out policy, or a LIFO policy. If we add and remove from the same location, the last item pushed onto the stack will be the first item removed from the stack. Another way to think about this is that the first item pushed onto the stack will be the last item popped off. We can push as many items as we want onto a stack, but in order to retrieve a specific item further down the stack, we must pop off each item to get to it. Once all items have been popped off the stack, the stack is empty. One example of a stack is the…

内容