# What is the difference between Stack and queue?

#1

Stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top . A stack follows the LIFO (Last In First Out) principle, i.e., the element inserted at the last is the first element to come out. The insertion of an element into stack is called push operation, and deletion of an element from the stack is called pop operation. In stack we always keep track of the last element present in the list with a pointer called top .

Queue: is a linear data structure in which elements can be inserted only from one side of the list called rear , and the elements can be deleted only from the other side called the front . The queue data structure follows the FIFO (First In First Out) principle, i.e. the element inserted at first in the list, is the first element to be removed from the list. The insertion of an element in a queue is called an enqueue operation and the deletion of an element is called a dequeue operation. In queue we always maintain two pointers, one pointing to the element which was inserted at the first and still present in the list with the front pointer and the second pointer pointing to the element inserted at the last with the rear pointer.

#2

Stack and Queue both are linear data structure.
Stack and Queue are used for inserting and deleting the elements .
The difference is Stack works in LIFO manner (Last in first out) where items that are inserted at the last are deleted first .
Whereas Queue works in FIFO manner ( First in first out) where items that are inserted first are deleted first.
One more difference is insertion and deletion operation in Stack is called as Push and Pop whereas in Queue it is called enque and deque respectively.

#3

Stack is a data structure which follows the policy of LIFO ( Last-In-First-Out). i.e. the element which is the last one to be inserted into the stack would be the First one to leave in case deletion is performed. Top is a variable(can be imagined to be a pointer) which stores the position of the topmost element of the stack. Elements are inserted into and deleted from the stack with the help of this variable.
Queue is a data structure which follows the policy of FIFO( First-In-First-Out) .i.e.
the element which is the first one to be inserted into the queue would be the First one to leave in case deletion is performed. Rear and Front are two variables which store the position of last and first element of the queue respectively.
New element is entered into the queue with the help of Rear variable. An element is deleted from the queue with the help of Front variable.