Answers for "stack stl"

C++
1

stack stl

#include <iostream>
#include<stack>
#include<algorithm>

using namespace std;

int main()
{
    stack<int>st;
    stack<int>st1;
    st.push(100);
    st.push(90);
    st.push(80);
    st.push(70);
    st.pop();
    st1.push(10);
    st1.push(20);
    st1.push(30);
    while(!st.empty())
    {
        cout<<st.top()<<" ";
        st.pop();
    }
    cout<<endl;
    while(!st1.empty())
    {
        cout<<st1.top()<<" ";
        st1.pop();
    }
    cout<<endl;
    st.push(100);
    st.push(90);
    st.push(80);
    st.push(70);
    st.pop();
    st1.push(10);
    st1.push(20);
    st1.push(30);
    st.swap(st1);
     while(!st.empty())
    {
        cout<<st.top()<<" ";
        st.pop();
    }
    cout<<endl;
     while(!st1.empty())
    {
        cout<<st1.top()<<" ";
        st1.pop();
    }
    cout<<endl;
    return 0;
}
Posted by: Guest on June-06-2021
9

stack c++

stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5
Posted by: Guest on April-26-2020
1

stack c++

#include <bits/stdc++.h> 

stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5
Posted by: Guest on November-02-2020

Browse Popular Code Answers by Language