Mobile Number Tracker
Trace Mobile Number Earn Money Online

Differences Between Stack and Queue

Enqueue and dequeue operations on a queue.
Samyak Lalit | April 1, 2016 (Last update: April 1, 2016)

Samyak Lalit is an Indian author and disability rights activist. He is the principal author and founder of projects like TechWelkin, WeCapable, Viklangta, Kavita Kosh among many others.

In programming courses, we all need to study data structures. Data structures are mechanisms in which data is organized in computer systems and used by computer programs. The aim of data structures is to organize data so as to use it in efficient way. All the students of computer programming are well aware of stacks and queues. These terms are often heard in algorithm classes. Stack and queue are among the simplest and most commonly used data structures. Let us understand what are the differences between stack and queue.

In very simple terms, a stack is a collection of objects in which objects are accessed in LIFO (Last In First Out) fashion. Whereas a queue is a collection of objects in which objects are accessed in FIFO (First In First Out) sequence.

What are the Differences between Stack and Queue?

Following are the major differences between these two data structures:

In a stack, an object is pushed on top of the collection during insertion operation. In a queue, new object is inserted at the end.

Difference between stack and queue.

Push and pop operations on a stack.

An object is removed from a stack from the top. In queue, object is removed from the beginning.

In stacks, the two operations allowed are called push (insertion) and pop (removal). In queue, two possible operations are called enqueue (insertion) and dequeue (removal).

Enqueue and dequeue operations on a queue.

Enqueue and dequeue operations on a queue.

In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added.

# Stack Queue
1 Objects are inserted and removed at the same end. Objects are inserted and removed from different ends.
2 In stacks only one pointer is used. It points to the top of the stack. In queues, two different pointers are used for front and rear ends.
3 In stacks, the last inserted object is first to come out. In queues, the object inserted first is first deleted.
4 Stacks follow Last In First Out (LIFO) order. Queues following First In First Out (FIFO) order.
5 Stack operations are called push and pop. Queue operations are called enqueue and dequeue.
6 Stacks are visualized as vertical collections. Queues are visualized as horizontal collections.
7 Collection of dinner plates at a wedding reception is an example of stack. People standing in a file to board a bus is an example of queue.

So these were the major differences between stack and queue data structures. We hope this article will be useful for you. Should you have any question on this subject, please feel free to ask us through comments section. We try to assist you. Thank you for using TechWelkin!


6 responses to “Differences Between Stack and Queue”

  1. Harsh says:

    good job sir ji thank u

  2. Anita says:

    I understood the differences

  3. enja says:

    woow it is good

  4. Aaron John Sabu says:

    It’s quite nice of you to explain it that way (a way different from as we learn it at school).

  5. Sohal says:

    thanks for this difference between and diagram
    good job!

Leave a Reply

Your email address will not be published. Required fields are marked *