stack and queue

A stack is a linear data structure where elements can be inserted and deleted only from one side of the list, called the "top". A stack follows the principle of "Last In First Out" in which the element inserted at the last is the first element to come out. The insertion of an element into stack is called push operation, while 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".

A queue is another linear data structure where elements can only be inserted from one side of the list that is "rear", and deletion of the elements can be done from the other side called the "front". The data structure of queue follows the principle of "First In First Out", in which the first element inserted in the list is the first element to be removed from the list. In a queue, the insertion of an element is called "enqueue operation", while deletion of an element is called "dequeue operation". In queue we usually prioritize two pointers, the front pointer pointing to the element which was inserted at the first and still present in the list, and the rear pointer pointing to the element inserted at the last.

Comments