Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Database / Difference Between Stack and Queue

Difference Between Stack and Queue

May 25, 2011 Posted by Indika

Stack vs Queue

Stack is an ordered list in which insertion and deletion of list items can be done only in one end called the top. Due to this reason, stack is considered as a Last in First out (LIFO) data structure. Queue is also an ordered list in which insertion of list items are done in one end called the rear, and the deletion of items are done in the other end called the front. This insertion and deletion mechanism makes the queue a First in First out (FIFO) data structure.

What is Stack?

As mentioned earlier, stack is a data structure in which elements are added and removed from only one end called the top. Stacks allow only two fundamental operations called push and pop. The push operation adds a new element to the top of the stack. The pop operation removes an element from the top of the stack. If the stack is already full, when a push operation is performed, it is considered as a stack overflow. If a pop operation is performed on an already empty stack, it is considered as a stack underflow. Due to the small number of operations that could be performed on a stack, it is considered as a restricted data structure. Additionally, according to the way that the push and pop operations are defined, it is clear that elements that were added last in to the stack go out of the stack first. Therefore stack is considered as a LIFO data structure.

What is Queue?

In a queue, elements are added from the rear of the queue and removed from the front of the queue. Since the elements that are added first will be removed from the queue first, it maintains the FIFO order. Due to this order of adding and removing elements, queue represents the idea of a checkout line. General operations supported by a queue are en-queue and de-queue operations. En-queue operation will add an element at the rear of the queue, while the de-queue operation removes an element from the front of the queue. In general, queues do not have a limit on the number of elements that can be added to the queue besides the memory constraints.

What is the difference between Stack and Queue?

Even though both the stacks and queues are kinds of ordered lists, they have some important differences. In stacks, adding or deleting items can be done only from one end called the top, while in queues adding items is done from one end called the rear and deleting items is done from the other end called the front. In a stack, items that are added last to the stack will be removed first from the stack. Therefore stack is considered as a LIFO data structure. In queues, items that are added first will be removed from the queue first. Therefore queue is considered as a FIFO data structure.

Related Link:

Difference Between Stack and Heap

Related posts:

Difference Between Stack and Heap Difference Between MySQL and Oracle Databases Difference Between MySQL and MS SQL Server Difference Between DBMS and File System Difference Between KDD and Data mining

Filed Under: Database Tagged With: de-queue, en-queue, en-queue and de-queue operations, FIFO, FIFO data structure, First in First out, First in First out data structure, Last in First out, Last in First out data structure, LIFO, LIFO data structure, push and pop operation, stack, stack overflow, stack underflow

About the Author: Indika

Indika, BSc.Eng, MSECE Computer Engineering, PhD. Computer Science, is an Assistant Professor and has research interests in the areas of Bioinformatics, Computational Biology, and Biomedical Natural Language Processing.

Leave a Reply Cancel reply

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

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Idea and Concept

Difference Between Idea and Concept

Difference Between Anaphase of Mitosis and Anaphase I of Meiosis

Difference Between Profession and Job

Difference Between Profession and Job

What is the Difference Between Fluorescence Microscopy and Confocal Microscopy

What is the Difference Between Fluorescence Microscopy and Confocal Microscopy

Difference Between Monorail and Metro Rail

Latest Posts

  • What is the Difference Between Elementary and Complex Reaction
  • What is the Difference Between Ataxia and Apraxia
  • What is the Difference Between Chlorine Fluorine and Astatine
  • What is the Difference Between B Cell and T Cell Leukemia
  • What is the Difference Between Animal Pole and Vegetal Pole
  • What is the Difference Between Terminal and Bridging Carbonyls
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018 Difference Between. All rights reserved. Terms of Use and Privacy Policy: Legal.