

enqueue() : It is used to add or insert an item to the queue.

The end from which the insertion happens in queue is known as REAR where as, the end from which the deletion happens is known as FRONT. we can imagine queue similar to the queue of people at a ticket counter in which first person at the queue will get the ticket and will get out from the queue. Unlike stacks queue is open from two ends in which insertion from one end and deletion from the other end. Queue is a linear data structure which is based on first in first out (FIFO) principle i.e, the element which have been inserted first will be removed first. isEmpty() : Returns true if stack is empty i.e, if there is no elements present in the stack.size() : It returns the current size of the size.peek() : It returns the element present at the top.pop() : It removes the element from the top and returns it value.push(x) : It is used to insert an element to the top of the stack.In stack,w e can only insert elements of same data type. In case of an array, we can access any element of an array at any time, whereas in a stack, we can only access the elements of the stack in the sequential manner. So, stack is basically a container which is closed from one end.

It is based on LIFO (last-in-first-out) principle in which both insertion and deletion takes place from one end only. In this article, we will be discussing about "Stack vs Queue" in detail.Ī stack is a linear data structure in which both insertion and deletion operation occurs at one end.
