DEV Community

Nikhita
Nikhita

Posted on

Stack vs queue

Stack and Queue are non-primitive data structures. They are used to store data. There are a few differences between them like

  1. Working Principle:
    Stack: LIFO(Last In First Out)
    Queue: FIFO(First In First Out)

  2. 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 queue

  3. Structure:
    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 insertion

  4. Number 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 queue

  5. Visualization:
    Stack: It is visualized as a vertical collection
    Queue: It is visualized as a horizontal collection

  6. Variants:
    Stack: It doesn't have any types
    Queue: It has three types- priority queue, circular queue and double ended queue.

  7. Implementation:
    Stack: It is more simple compared to queue
    Queue: It is comparatively more complex than stack

Top comments (0)