C++ 棧的應用實例

有一個整數集合{23,56,11,4,87,98},將它們依此存入某數據結構,然後輸出,要求輸出的順序爲:11,4,56,98,87,23

#include<iostream>
#include"stack.h"
using namespace std;
int main()
{
stack<int>s=stack<int>(6);
int temp=0;
s.push(23);
s.push(56);
s.push(11);
temp=s.pop();
cout<<temp<<"";
s.push(4);
temp=s.pop();
cout<<temp<<"";
temp=s.pop();
cout<<temp<<"";
s.push(87);
s.push(98);
temp=s.pop();
cout<<temp<<"";
temp=s.pop();
cout<<temp<<"";
temp=s.pop();
cout<<temp<<"";
return 0;
}


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