A stack is a data structure it serves as a collection of elements. It has 2 principle operation push and pop.
The push operation pushes the element on the top and the pop operation removes the element on the top. This can be seen in the below image.
Stack works on the principle of Last In First Out or LIFO i.e the element that is entered last is removed first.
Stacks can be implemented using arrays as well as linked list.
There are a lot of applications of Stacks like
- Recursion
- Backtracking
- Memory management
- Activation records etc
The following program is to implement a stack using an array with maximum size of 20.
C Program
C++ Program
You might also be interested in
Linked List in python
Linked List in C++
Finding the next Smallest Palindrome
Finding factorial of a number
Bar Graph in C using dda Line generation algorithm
Comments
Post a Comment