Difference Between Stack and Queue

Main Difference – Stack vs Queue

In Computer Science, stack and queue are two abstract data types that are simple data structures that use pointers to represent dynamic sets. However, a difference can be noted between them based on their implementations. Basic operations of inserting and deleting elements are supported by both stack and queue. The main difference between Stack and Queue is that a stack implements Last In First Out or LIFO policy, whereas a queue implements First In First Out or FIFO policy.

What is Stack

A stack is a linear data structure that serves as a collection of elements. Only one end of the structure is accessible to perform operations on elements, and it is commonly referred to as the top. Two principal operations can be performed on a stack; push and pop. An ‘insert’ operation performed on a stack is called push and a ‘delete’ operation performed on a stack is called pop.

The push operation adds an element to the top of the collection. Performing a pop operation removes an element that is at the top of the collection. Since the elements that are removed from the stack are in reverse order to the order of their addition, the structure is known to follow Last In First Out or an LIFO approach. Given this implementation, the lowest elements have been on the stack for the longest.

A stack is considered as a restricted data structure due to the small number of operations that can be performed on a stack. Additionally, a peek operation can be implemented to return the value of the top element without modifying the element. Also, implementations of a stack often have an IsEmpty function to check whether the stack is empty. In environments that rely heavily on stacks, functions like delete, swap/exchange and rotate may also be provided. But these are not essential for the basic functionality of a stack.

A stack has a bounded capacity. If the stack is full, it goes into an overflow state, which means there is not enough space for more elements to be pushed onto the stack. If the stack is empty, and there are no elements to pop, the stack is in an underflow state.

A stack can be easily implemented using arrays or linked lists in most high-level programming languages.

Stacks are applicable in areas such as evaluating arithmetic expressions, run-time memory management, tree traversal, syntax parsing, etc.Difference Between Stack and Queue

What is Queue

A queue is a linear data structure that also serves as a collection of elements. Both ends of a queue are accessible for performing operations on elements and are typically called head and tail. Two principal operations can be performed on a queue; enqueue and dequeue. Enqueue is the insertion operation while dequeue is the deletion operation performed on a queue.

When an element is enqueued, it is added to the tail of the queue. Performing a dequeue operation will remove an element from the head of the queue. Since the enqueued elements are always dequeued in the same order as they were enqueued, the structure is said to implement a First In First Out or FIFO approach.

Similar to a stack, a queue is also a restricted data structure given the small number of operations that can be carried out. In addition, a peek operation can be implemented in a queue, which will return the value of the element at the head of the queue without dequeuing it. Other primitive operations on a queue may include IsEmpty, IsFull, and display. The IsEmpty function checks whether the queue is empty and IsFull check if the queue is full. The display function can be used to present the content of the queue. But again, these functions are not critical for the implementation of a queue.

 Unlike a stack, queues can be implemented to have a bounded capacity or with no specific capacity. An overflow state of a queue occurs when an element is enqueued to a full queue, and an underflow state occurs when an element is dequeued, but the queue is empty.    

The type of queue may differ on how enqueuing and dequeuing operations are performed on elements. Circular queue, priority queue, and double-ended queue are the special types of queues.

Using arrays and linked lists, queues can be efficiently implemented in high-level programming languages.

Queues are applicable in many areas such as simulations, batch processing in operating systems, scheduling algorithms, buffering requests, multiprogramming platform systems, etc.

Main Difference - Stack vs Queue

Difference Between Stack and Queue

Accessibility to Elements

 In a stack, operations on data can be performed only at the top of the stack.

 In a queue, both ends of the queue are accessible for operations. An insertion takes place at the tail of the queue, and a deletion can be made at the head.


A stack is an LIFO data structure, where the element that was added last to the stack is the first element to be removed. The removal is in reverse order to the order of addition.

A queue is an FIFO data structure, where the element that was added first to the queue will be the first element to be removed. Order of insertion and removal are the same.

Basic Operations

In a stack, an element is inserted at the top of the stack and removed from the top as well.

But in a queue, an element is inserted at the end of a queue and is removed from the front.


A stack has a bounded capacity.

 A queue can be of bounded capacity, but is usually implemented without a specific capacity.

Wastage of Memory Space

Since a stack only needs one pointer to keep track of the top of the stack, there is no wastage of memory space.

A queue needs two pointers ‘front’ and ‘rear’ to keep track of both ends of the queue. Therefore, there is wastage of memory space.

Stack vs. Queue – Summary

Both stack and queue are used for the purpose of maintaining ordered lists of elements. While a stack is an LIFO data structure, a queue implements an FIFO approach. Only one end of a stack is accessible for principal operations, but both ends of a queue can be used. 

About the Author: admin

Related pages

static and round characterscharacteristics victorian period literatureproperties of vulcanized rubberdistinguish between intrinsic and extrinsic semiconductordifference turtles and tortoisesidioms to kill a mockingbirddefinition of meristematic tissuedefinition of nonvascularbasophil eosinophil neutrophilflashback definition and exampleswhat are normative economicseminent antonymdifference of legend and mythmoral lesson of ugly ducklingvolatile substance chemistrydifference between monocot and dicotbulldogs vs pitbullsquantity of adjectivehow does a spectrophotometer measure absorbancemetaphor vs allegoryadage definedwhat are microtubules and microfilamentsfinancial projections for bank loananimal farm personificationconsonant typesdifference between american rottweiler german rottweilerrelationship between mass and inertiawhat is the crust composed ofwhat is malleable and ductileatp and adp moleculesexamples of types of nounswhat is the difference between homogenous and heterogenous mixturepermanent and temporary magnetscharacteristics of alkenesfennel jeeradefinition for boiling pointdefine paramagnetismconfessional poetry examplesaction versus linking verbsspectroscopic gayetydefine monounsaturated fatswhats a predicate adjectivewarm blooded vs cold bloodedtypes of poems sonnetrotary motion meaningmeaning of snuggleswhat is the difference between constructive and destructive forcesdefine valence electronsdifference between flair and flaredifference between fungal and bacterial jock itchallegory metaphorcaribou vs moosewhat is the difference between a solute and a solventkingdom monera archaebacteriadifference between narcolepsy and cataplexywhat are cilia and flagella composed ofparaphrasing vs summarydifferences between npn and pnp transistorfiancée definitionlimerick rhyming schemedifference between condominium and apartmentwhat is dextrin derived fromdifference between utc and estequity vs equality in educationprophase characteristicsferrous metal and non ferrous metal differencepast tense of arisedifference between evaporation and transpirationwhen did the art nouveau movement begincaramel vs butterscotchwhat is predicate nominative exampleswhat is the difference between an aldose and a ketosewhat is the difference between russia and the russian federationanalogy and similewhat is the difference between a bishop and an archbishoprelationship between phonetics and phonologythe difference between phd and doctoratedash hyphen differenceamino acids essential and nonessentialartificial sweeteners vs natural sweetenerswhat is the difference between tiger and leopardhow to find the area of a heptagon