超大哥作業

//freopen("hao.in","r",stdin);
//atoi(s[i].c_str());
//建立一個順序棧以及基本操作
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define FOR(i,l,r) for(int i=l;i<=r;i++)
const int N = 10005;
using namespace std;
int top;                        //棧頂,初始爲0,第一個元素爲1
int stack[N];					//數組模擬棧
void push()
{	
	int data=0;					//輸入數據
	cin>>data;
	stack[++top]=data;	
}
void pop()					
{
	cout<<stack[top]<<endl;
	top--;
}
void display(int n)
{
	if(n<=0){
		cout<<endl;
		return;		
	}
	cout<<stack[n]<<" ";
	display(n-1);
}
int main()
{
	string comd;                //命令操作
	for(;;)
	{
		cin>>comd;
		if(comd=="push")       	//輸入
			push();
		else if(comd=="pop")	//彈出
			pop();
		else if(comd=="display")	//顯示
			display(top);
		else if(comd=="exit")		//退出
			break;
	}
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章