栈模板--实现数据的逆序输出

#include<iostream>
#include<stack>
using namespace std;
int n=10;
int main(){
	stack<int>s;
	int a[]={1,2,3,4,5,6,7,8,9,10};
	for(int i=0;i<10;i++){
		s.push(a[i]);
	}
	for(int i=0;i<10;i++){ 
		printf("%d ",s.top());
			s.pop();
	} 
} 

输出结果:

10 9 8 7 6 5 4 3 2 1
--------------------------------
Process exited after 0.3249 seconds with return value 0
请按任意键继续. . .

 


版权声明:本文为queque_heiya原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。