how to print stack in c++ code example
Example 1: stack c++
stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5
Example 2: print stack c++
while(!myStack.empty()) {
cout << myStack.top() << " ";
myStack.pop();
}
Example 3: size of stack in c++
std::stack<int> st;
std::cout << "size of stack: " << st.size();