Stack-to-stack operation

First, simply enter n, which represents the number of digits entered, then push the stack sequentially, and then pop the stack to output each number.
(The stack is a first-in-last-out data structure)

#include <iostream>
#include<stack>
using namespace std;

int main()
{
    
    

    stack<int> s;

    int n;
    int t;

    scanf("%d",&n);

    for(int i=0; i<n; i++)//进栈操作
    {
    
    
        scanf("%d",&t);
        s.push(t);


    }


    for(int i=0; i<n; i++)//出栈操作
    {
    
    

        cout<<s.top()<<" ";
        s.pop();
    }




    return 0;
}

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45976312/article/details/109108866