Stack is a linear data structure which works on the principle of LIFO Last In First Out. Removal of an element from a stack is called pop. And insertion of an element in a stack is known as push. Push and Pop both operations in a stack is done on top of the stack.
Real life examples of a stack is the arrangement of plates in a public food court. The plates are arranged in a manner one above another. That arrangement is a stack. Because you can see the last plate placed is used first. Which is basic principle of Stack.
Implementation of stack in computer are various for example.
- Undo and redo function in editor.
- Forward and backward feature in web browser.
- Checking opening and closing of brackets or parentheses in an expression.
- Evaluation of infix, postfix or prefix expressions.
- Backtracking means ability to again reach the old path as in a game of maze.
In programming stack is implemented by two ways
- Using Array in this size of stack is pre defined.
- Using linked lists in this the size of Stack can be anything according to our program.
Queue is a linear data structure which works on the principle of FIFO First In First Out. Removal of an element from a Queue is called Dequeue. And insertion of an element in a Queue is known as Enqueue. Generally the entry of elements in Queue is done from rear and deletion from front.
There are various type of queues as follows:-
- Simple queue : it is a simple linear queue with front and rear.
- Circular queue: In this type of queue the last node is connected to first node and forms a circular queue.
- Priority queue: In this queue every element has priority and the operation are performed according to that.
- Double ended queue: This queue has ability to insert and remove elements from both ends.
Real life examples of a Queue is the Queue of people we see in various places. Here whoever comes first is served first.
Implementation of Queue in computer are various as follows:-
- CPU scheduling it means the order of various task given to a system follows various queue algorithms.
- In giving print commands, where all documents are ordered with the help of queue.
- Handling of interrupts in systems.
- In real life, Call Center phone systems use Queues, to hold people calling them in an order, until a service representative is free.
In programming Queue is implemented by two ways:-
- Using Array, in this size of Queue is pre defined.
- Using linked lists in this size of queue can be anything according to our program.
For C program for various operations on a queue visit|
For C program for various operations on stack visit|https://www.devlopersguide.com/c-program-to-implement-stack-using-array/
For more programming stuff visit| https://www.devlopersguide.com/category/programming/
For any feedback or queries comment down below.