Stack
- An ordered list.
- Deletion and insertion all made at one end i.e., LIFO (last in first out)
- Stack has basic three operations which can be performed on stack, namely
push
,pop
, andpeek
push
: to insert an elementpop
: to remove the topmost elementpeek
: to look what's at the top of the stack without removing it- Every stack operation takes constant time. O(1)
Stacks are usually not dynamic in nature, if implemented using static arrays. But they can be made dynamic using linkedlists or dynamic lists in python.
To see the implementation of stack
using linkedlist
click here.
How to use a stack in python?
install the data structure library using
Example
A few applications of stacks
- Post fix notation
- Recursion
- Fibonacci series
- permutations ...... etc.