Stack and Queue are non-primitive data structures. They are used to store data. There are a few differences between them like
Working Principle:
Stack: LIFO(Last In First Out)
Queue: FIFO(First In First Out)Operations:
Stack: Pop and Push. Pop operation removes element from list whereas, push operation inserts element in a list.
Queue: Dequeue and Enqueue. Dequeue operation removes element from queue whereas, enqueue adds element to a queueStructure:
Stack: Has only one end from where both insertion and deletion takes place, known as a top
Queue: Has two ends i.e., front and rear end. Front end is used for deletion whereas, rear end is used for insertionNumber of points used:
Stack: Contains only one pointer known as the top pointer. It holds the addresses of the last inserted element of the stack
Queue: Contains two pointers, front and rear. Front pointer holds address of first element whereas rear pointer holds address of last element in the queueVisualization:
Stack: It is visualized as a vertical collection
Queue: It is visualized as a horizontal collectionVariants:
Stack: It doesn't have any types
Queue: It has three types- priority queue, circular queue and double ended queue.Implementation:
Stack: It is more simple compared to queue
Queue: It is comparatively more complex than stack
Top comments (0)