githubEdit

Stack Basics

In C++ STL has stacks built in, nothing to fear!

6.1 Push

Insert something to the stack.

#include<iostream>
#include <stack>

using namespace std;

void stack_push_stl() {
    stack<int> st;
    st.push(5);
    cout << st.top() << "\n";
}

int main() {
    stack_push_stl();
    return 0;
}

6.2 Pop

Delete something from the stack!

But if you want to implement this manually like STL does?

Stack Library

An example stack class template,

Last updated

Was this helpful?