![]() |
What’s difference between Stack and Queue?
What’s difference between Stack and Queue?
|
Queues and Stacks are used as containers to hold objects and retrieve them out in a specific order, which facilitates different types of operations. A Stack operates as a First In Last Out (FILO) container while a Queue operates as a First In First Out (FIFO) container.
|
In stack insertion and deletion of items can be done only on one end that is "TOP".
In queue insertion can be done in one end called "REAR" and deletion is done at the other end called "FRONT". |
In a stack, objects are inserted and removed at the same ends. In a queue, objects are inserted and removed at the different ends.
Stack follows Last in first out order. Queue follows first in first out. |
A stack is a collection of elements, which can be stored and retrieved one at a time. Elements are retrieved in reverse order of their time of storage, i.e. the latest element stored is the next element to be retrieved.
A queue is a collection of elements, which can be stored and retrieved one at a time. Elements are retrieved in order of their time of storage, i.e. the first element stored is the next element to be retrieved. |
The stack is a container of objects that are inserted and removed according to the (LIFO) principle.
The queue is a container of objects (a linear collection) that are inserted and removed according to the (FIFO) principle. |
Stack and queue both are data structure that we used in programming to control the flow of data in efficient way. Stack act like a box of cardboard in which the First cardboard piece that have stored can be only retrieve in last. But Queue is a box which has also tore from the bottom, in this 1st piece of cardboard will retrieve first.
|
Stack act as a A Room that has only one door and the person who enter in this room along with other people will be last to leave the room. But Queue is like cave that has two ending with one enter and one exit gate and arranged in such way that first one who has enter in this cave will be first to leave the cave through exit gate.
|
All times are GMT -7. The time now is 09:31 AM. |
Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.