Stack

A stack is a linear data structure that follows the Last In First Out (LIFO) principle. In a stack, elements are inserted and removed from the same end, known as the top of the stack. The operations on a stack are as follows:

  1. Push: Add an element to the top of the stack.

  2. Pop: Remove and return the element at the top of the stack.

  3. Peek: Return the element at the top of the stack without removing it.

  4. isEmpty: Check if the stack is empty.

Stacks can be implemented using arrays or linked lists. The array-based implementation is more common due to its simplicity and efficiency.

Monotonic Stack


Copyright © 2024 Syed Fahad Sultan. Distributed by an MIT license.