c++基礎-棧

c++中棧的基本使用代碼如下:

#include <iostream>
#include <stack>
using namespace std;
 int main(){
 	stack<int> s;
 	for(int i=2;i<10;i++){
 		s.push(i);//從棧頂加入
 	}
 	cout<<s.size()<<endl;
 	while(!s.empty()){
 		cout<<s.top()<<" ";//返回棧頂元素
 		s.pop();//刪除棧頂元素
 	}
 	return 0;
 }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章