Skip to content

Latest commit

 

History

History
8 lines (4 loc) · 1003 Bytes

File metadata and controls

8 lines (4 loc) · 1003 Bytes

What is the difference between a stack and a queue?

Both stack and queue are linear data structures used to store and manipulate collections of elements, but they have different characteristics and operations.

A stack is a Last-In-First-Out (LIFO) data structure. This means that the last element added to the stack is the first one to be removed. In a stack, elements are inserted and removed from the same end, which is called the top of the stack. The basic operations of a stack are push (add an element to the top of the stack) and pop (remove the top element from the stack).

A queue, on the other hand, is a First-In-First-Out (FIFO) data structure. This means that the first element added to the queue is the first one to be removed. In a queue, elements are inserted at one end, called the rear, and removed from the other end, called the front. The basic operations of a queue are enqueue (add an element to the rear of the queue) and dequeue (remove the front element from the queue).