Stack

A LIFO (Last In, First Out) data structure supporting push, pop, and peek operations in O(1). Used in recursion, undo systems, and expression parsing.

Syntax

dsa
push(item)  // add to top
pop()        // remove from top
peek()       // view top without removing

Example

dsa
// JavaScript using array:
const stack = [];
stack.push(1);       // [1]
stack.push(2);       // [1, 2]
stack.push(3);       // [1, 2, 3]
stack.pop();         // returns 3, stack: [1, 2]
console.log(stack[stack.length - 1]); // peek: 2