Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A container adapter that follows the Last-In, First-Out (LIFO) principle. Elements are pushed and popped from only one end (the top).
push(val): Adds element to top.pop(): Removes top element.top(): Returns top element (doesn't remove).empty(): Checks if stack is empty.stack<int> s; s.push(10); s.push(20); cout << s.top(); // 20 s.pop(); cout << s.top(); // 10
Used for reversing data, balancing brackets, function calls (recursion stack), and evaluating mathematical expressions.