Labs ICT
🎓 SIWES/IT Login

Stack

1 min read | C++ Tutorial
🎓

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

C++ Stack

std::stack follows the LIFO (Last In, First Out) principle. Elements are added with push(), removed with pop(), and the top element is accessed with top(). Stacks are useful for undo operations, expression evaluation, and depth-first traversal.

#include <iostream>
#include <stack>

int main() {
    std::stack<int> s;
    s.push(10);
    s.push(20);
    s.push(30);
    std::cout << "Top: " << s.top() << "\n";
    s.pop();
    std::cout << "Top after pop: " << s.top();
    return 0;
}