首页 > 试题广场 >

#includeusing&nb...

[单选题]
#include<bits/stdc++.h>
using namespace std;
int main(){
stack<int>st;
int pos = 1;
while(pos <= 3){
st.push(pos++);
}
cout<<st.top();
while(pos <= 5){
st.push(pos++);
}
while(!st.empty()){
cout<<st.top();
st.pop();
}
return 0;
}


上述程序的输出为(      )
  • 35421
  • 354321
  • 12453
  • 123453
注意:3没有pop出来,只是输出了st的top
发表于 2019-09-21 14:53:49 回复(0)
压栈:1,2,3,输出3
压栈:4,5,输出栈内所有:5,4,3,2,1
答案:354321
编辑于 2019-08-28 16:31:42 回复(0)