1. 程式人生 > >stack使用方法

stack使用方法

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


void test01()
{
//初始化
stack<int> s1;
stack<int> s2;
vector<int> s3;


//stack 操作;
s1.push(10);
s1.push(20);
s1.push(30);
s1.push(100);

cout << "棧頂元素" << s1.top() << endl;
s1.pop();//刪除棧頂元素


//列印棧容器的資料
while(!s1.empty())
{
cout << s1.top() << " ";
s1.pop();
}
cout << endl;
cout << "size = " << s1.size() << endl;
//cout << "capacity = " << s1.capacity() << endl;
//作業1 棧容器存放物件指標
//作業2 棧容器存放物件
}


int main(int argc, char *argv[])
{
test01();
return 0;
}