Skip to content

Latest commit

 

History

History
26 lines (13 loc) · 819 Bytes

stackQueue.md

File metadata and controls

26 lines (13 loc) · 819 Bytes

Difference between a stack and a queue.

Stack


A stack is a container of objects that are inserted and removed according to the LIFO (last-in first-out) principle.

It is a limited access data structure. Elements can be added and removed from the stack only at the top.

push adds an item to the top of the stack, pop removes the item from the top.

Easy analogy is to think of a stack of books.

A stack is a recursive data structure. A stack is either empty or it consists of a top and the rest which is a stack.

Queue


Container of objects that are inserted and removed according to the first-in first-out FIFO principle.

Example: line of students getting food. New additions to a line is made to the back of the queue, while removal happens in the front.