栈 链式结构
一個概念:
C++ STL - stack
代碼:
#include<iostream> #include<stack>//頭文件using namespace std; int main() {stack <int> stk;//創建一個棧,名為stk,元素類型為int cout<<"1: push 2: pop 3:size of zhan 4: the top number 5:empty?"<<endl;char ch;paji: cin>>ch;switch(ch){case '1':{//元素進棧cout<<"The number of numbers to insert:";int num;cin>>num;while(num--){int a;cin>>a;stk.push(a);}break;}case '2':{//使棧頂部的元素出棧,返回void類型cout<<"The number of numbers to be stacked:";int k;cin>>k;while(k--){stk.pop();}break;}case '3':{//返回棧的大小,有多少元素cout << stk.size() << endl;break;}case '4':{//top() 返回棧最頂部的元素,且不改變棧cout << stk.top() << endl;break;}case '5':{//查看棧是否為空,如果為空,返回真(1)cout << stk.empty() << endl;break;}}goto paji;return 0; }
今天也是元氣滿滿的一天!good luck!
轉載于:https://www.cnblogs.com/cattree/p/7535821.html
總結
- 上一篇: 【差分】bzoj 1676 [Usaco
- 下一篇: ModelAndView学习笔记