课程: C# 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 a series of ordered objects, just like a list, but similar to a queue, the way we add access 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. 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 the stack, but in order to retrieve a specific item, we must pop off each item in front of it to get it. Once all the items have been popped off the stack, the stack is empty. One example of a stack is the runtime…

内容