Differences Between Stack and Queue

April 1, 2016

Learn the major differences between stack and queue data structures. It is a common question in programming language courses and exams.

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.

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.

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!

Lalit Kumar is the Principal Author and Founder of TechWelkin. He is a web explorer and he enjoys finding useful information on the Internet. He loves to put things together to create a bigger solution. Lalit is passionate about technology, languages and literature. You can contact Lalit via email (techwelkin [at] gmail [dot] com) or Facebook (facebook.com/techwelkin).