Sign InCoursewareNuggetsTutorials AboutClassesCodePad

What is a Stack?

Imagine a stack of books on a desk. If you want to add a book, you add it to the top of the stack. To get a book from the stack, you start from the top as well. A stack has a top and a bottom. We can add and remove only from the top.

stack of books

In computer science, a stack is a limited access data structure - elements can be added and removed from the stack only at the top. Two operations are allowed to modify a stack: push adds an item to the top and pop removes an item from the top. The most recently added item is the one that is in position to be removed first. This ordering principle is called the last-in first-out (LIFO) principle.

stack data structure.
stack push operation.
stack pop operation.
© CS Wonders·About·Classes·Cheatsheet