6
Reply

What is the difference between stack and queue?

Pankajkumar Patel

Pankajkumar Patel

Sep 18
693
1
Reply

    Stack : Stack is works on Last in First out (LIFO) principle . Means elements are add and remove only one way .

    Queue : Queue is works on First out First out (FIFO) principle . Which means elements are add first into queue is also remove first .

    The main difference between a stack and a queue is the order of data operations— how elements are added and removed. In a stack, data is added last and removed first (Last In, First Out – LIFO), whereas in a queue, data is added first and removed first (First In, First Out – FIFO). Example of Stack: Function evaluation Examples of Queue:Task scheduling, message queues and many more

    Stack vs Queue
    Feature Stack Queue
    Definition A linear data structure that follows LIFO (Last In, First Out). A linear data structure that follows FIFO (First In, First Out).
    Insertion/Deletion Happens at the same end (top). Happens at different ends — insert at rear, remove from front.
    Example Stack of plates — last plate kept is removed first. Queue of people — first person in line is served first.
    Main Operations push(), pop(), peek() enqueue(), dequeue(), front()

    Stack => Last in - First Out
    you can see it in Ctrl+Z

    Queue => First in - First Out
    you can see it in Sending Message

    Papa's Games’s amazing how addictive the simple loop of taking orders and prepping food can be.

    Your essay kept me engaged from start to finish. It’s clear, concise, and very well-structured [escape road 2](https://escaperoad2.io). I’ve read quite a few articles on this topic, but yours stands out for its clarity and thoughtful approach.
    nancy
    Nov 13
    0