Difference between Stack and Queue
Difference between Stack and Queue
=================================================================================
Stack : A stack is a direct information structure in which components can be embedded and erased exclusively from one side of the rundown, called the top. A stack follows the LIFO (Rearward In First Out) rule, i.e., the component embedded at the latter is the main component to emerge. The inclusion of a component into the stack is called push activity, and the erasure of a component from the stack is called pop activity. In stack, we generally monitor the last component present in the rundown with a pointer called top.
Queue : is a linear data structure in which elements can be inserted only from one side of the list called rear, and the elements can be deleted only from the other side called the front. The queue data structure follows the FIFO (First In First Out) principle, i.e. the element inserted at first in the list, is the first element to be removed from the list. The insertion of an element in a queue is called an enqueue operation and the deletion of an element is called a dequeue operation. In queue, we always maintain two pointers, one pointing to the element which was inserted at the first and still present in the list with the front pointer and the second pointer pointing to the element inserted at the last with the rear pointer.
STACK |
QUEUE |
· Stack is LIFO or FILO utility data structure |
Queue is FIFO utility data structure |
· Push and pop operations are done from the same
end i.e. TOP |
Push and operations are done from different
ends i.e. rear and front respectively |
· Application: Function activation records are created on the stack for each
function call |
Application: Printer maintains queue of
document to be printed |
· There are no types of stacks. However, in
single array we can implement two or more stacks (called as multi-stack
approach) |
There four types of queues i.e. linear, circular,
priority and deque |
· To solve infix expression by converting to
prefix or postfix |
OS uses queues for many functionalities: Ready
queue, Waiting queue, Message queue |
· Parenthesis balancing |
|
· To implement algo likes Depth First Search |
To implement algo likes Breadth First Search |
Comments
Post a Comment