What Is Stack
. Linear Data Structure
TWO OPERATION :
1 - PUSH : Entering the data on the top or at the end
2- POP : Remove the top element or latest element
So, Stack performs LIFO operation where LIFO stands for Last In First Out.
Nowadays every language has some more operations i.e. Peek, Is empty, Is full , size
3 - PEEK : It help us to check the top entry without deleting it
4- IS EMPTY : this checks whether the stack is empty or not and provides boolean value (true / false)
5- IS FULL : this checks whether the stack is full or not in non dynamic data structure. If you are using standard library then it resize dynamically .
6- SIZE : this gives the size of the stack
Whenever you get stack , think it to be a data structure where you have to preform insertions and deletion on the same end what ever data structure you are using.
Real Life Example :
1- Plates stacked over one another
2- Stacked books
So , the book on top is the first book to be taken . Although it was the last book to place . Similarly
in marriages the top most dinner plate is the first plate to be taken and used.
APPLICATION OF STACK
1- Undo - Redo features
2- Infix to Prefix or Postfix
3- Balancing the symbols
4- Used in Algorithms
a) Rat in maze
b) N Queen Problem
c) Tower of Hanoi
d) Stock span problem
e) Topological Sorting
f) Strongly Connected Components
5- Syntax Parsing
6- Browser back button
7- Useful for performing operations like Backtracking in Programming
IMPLEMENTATION
You can use any data structure to perform this operation :
1- Array
2- Linkedlist
If you use standard library , you can use the data structure provided such as stack (we will see the implementation soon ) which is dynamic and provided certain operations.
No comments:
Post a Comment