Difference Between Stack and Queue

Difference Between Stack and Queue in Tabular Form

Comparison Between Stack and Queue 

The major difference between a Stack and a Queue is that stack is a LIFO type while Queue is a FIFO type data structure. LIFO stands for Last In First Out i.e if we put data in a stack then the last entry will be processed first. While FIFO stands for First In First Out it means the first entry in a queue will be processed first.

Comparison Between Stack and Queue
Comparison Between Stack and Queue  in Data structure

Comparison Chart

Stack Queue
A Linear List Which allows insertion or deletion of an element at one end only is called Stack A Linear List Which allows insertion at one end and deletion at another end is called Queue
Since insertion and deletion of an element are performed at one end of the stack, the elements can only be removed in the opposite order of insertion. Since the insertion and deletion of an element are performed at the opposite end of the queue, the elements can only be removed in the same order of insertion.
A stack is called as Last In First Out (LIFO) List A queue is called First In First Out (FIFO) List.
The most and least accessible elements are called
as TOP and BOTTOM of the stack
Insertion of the element is performed at the FRONT end
and deletion is performed from the REAR end
Example:  Stack is arranging plates in one above
one.
Example: Ordinary queue in provisional store.
Insertion operation is referred to as PUSH and
deletion operation is referred to as POP
Insertion operation is referred to as ENQUEUE and
deletion operation is referred to as QUEUE
Function calling in any languages uses Stack Task Scheduling by Operating System uses a queue
To check if a stack is empty, the following condition is used:
TOP == -1
To check if a queue is empty, the following condition is used:
FRONT == -1 || FRONT == REAR + 1
To check if a stack is full, the following condition is used:
TOP == MAX – 1
To check if a queue is full, the following condition is used:
REAR == MAX – 1
A Stack requires only one reference pointer. A Queue requires two reference pointers.




Stack

  • The condition to check if a stack is empty:
int isEmpty() 
{ 
if(top==-1) 
return 1; 
else return 0; 
}
  • The condition to check if a stack is full
int isFull()
{
    if(top==MAX-1)
        return 1;
    else
        return 0;
}

Queue

  • The condition to check if a queue is empty:
int isEmpty()
{
    if(front==-1 || front==rear+1)
        return 1;
    else
        return 0;
}
  • The condition to check if a queue is full:
int isFull()
{
    if(rear==MAX-1)
        return 1;
    else
        return 0;
}




More Differences