You are on page 1of 3

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.
Differences between Stacks queues:
Stacks
Stack is a heap of elements placed one
over the other
Stack mechanism is known as Last In
First Out (LIFO)
Stack is mainly characterized by top
which refers to its top element.
Both insertion and deletion occur at
the same end i.e. at the top.
If there is no value at the top, stack is
said to be empty.
The common terms associated with
stack are : push, pop, top, isfull,
isempty.

Stack can be implemented using both


arrays and linked lists.
This has no sub types

Queues
Queue is a set of elements placed one
after the other
Queue mechanism is known as First In
First Out (FIFO)
Queue is mainly characterized by
front and rear, which refers to its first
and last elements.
Insertion and deletion occur at two
different ends i.e. insertion at rear and
deletion at front.
If front=rear, queue is said to be empty.
The common terms associated with
queue are: qinsert, qdelete, front, rear,
isfull, isempty.

Queue also can be implemented using


both arrays and linked lists.
It has sub types such as: simple queue,
circular queue, double-ended queue,

priority queue.

You might also like