# Stack vs Queue

Posted September 10, 2022 by Rohith and Anusha ‐ 2 min read

The primary difference between Stack and Queue Data Structures is that Stack follows LIFO while Queue follows FIFO data structure type. LIFO refers to Last In First Out. It means that when we put data in a Stack, it processes the last entry first. Conversely, FIFO refers to First In First Out. I

Difference Between Stack and Queue are stated below

ParameterStack Data StructureQueue Data Structure
BasicsIt is a linear data structure. The objects are removed or inserted at the same end.It is also a linear data structure. The objects are removed and inserted from two different ends.
Working PrincipleIt follows the Last In, First Out (LIFO) principle. It means that the last inserted element gets deleted at first.It follows the First In, First Out (FIFO) principle. It means that the first added element gets removed first from the list.
PointersIt has only one pointer- the top. This pointer indicates the address of the topmost element or the last inserted one of the stack.It uses two pointers (in a simple queue) for reading and writing data from both the ends- the front and the rear. The rear one indicates the address of the last inserted element, whereas the front pointer indicates the address of the first inserted element in a queue.
OperationsStack uses push and pop as two of its operations. The pop operation functions to remove the element from the list, while the push operation functions to insert the element in a list.Queue uses enqueue and dequeue as two of its operations. The dequeue operation deletes the elements from the queue, and the enqueue operation inserts the elements in a queue.
StructureInsertion and deletion of elements take place from one end only. It is called the top.It uses two ends- front and rear. Insertion uses the rear end, and deletion uses the front end.
Full Condition ExaminationWhen top== max-1, it means that the stack is full.When rear==max-1, it means that the queue is full.
Empty Condition ExaminationWhen top==-1, it indicates that the stack is empty.When front = rear+1 or front== -1, it indicates that the queue is empty.
VariantsA Stack data structure does not have any types.A Queue data structure has three types- circular queue, priority queue, and double-ended queue.
VisualizationYou can visualize the Stack as a vertical collection.You can visualize a Queue as a horizontal collection.
ImplementationThe implementation is simpler in a Stack.The implementation is comparatively more complex in a Queue than a stack.