What is the Stack Data Structure?

In Computer Science and programming, a data structure simply is how a particular set of data values is arranged, stored, and managed.

Going forward, I’d like you to think of the word ’stack’ in its literal sense. What comes to mind? A bunch of books well-arranged? Right. A pile of plates? Also right.

A stack consists of data items, and it allows one to insert or delete the item at the top end of the stack. The insert operation in the stack data structure is referred to aspush while the delete operation is called pop

Image for post

Stack operations happen at the top of the stack only, that is on the last element to be added

Welcome the LIFO Concept!

Last In, First Out, LIFO, is used to describe the order by which Stack operations are executed. The last data element to be added is the first element to be retrieved. Also, a new data element is added at the top of the stack.

What are Stacks used for?

  1. The stack data structure is applied in undo and redo operations in word processing and graphic editing software
  2. Recursive functions in programming use the stack data structure. When a function is called, the function goes to the top of the stack.

#coding #data-structures #python #algorithms

Stacks in Python
1.80 GEEK