栈(进、出栈,判是否为空)
#include <iostream>
#include<stdlib.h>
#define Max 6
using namespace std;
typedef struct zhan{
int date[Max];
int top;
};
void initzhan(zhan *&s){
s=(zhan *)malloc(sizeof(zhan));
s->top=-1;
}
bool judge(zhan *s){
if(s->top==-1) return true;
return false;
}
void push(zhan *&s,int e){
if(s->top==Max-1)
cout<<"数据溢出"<<endl;
s->date[++s->top]=e;
}
bool pop(zhan *&s,int &e){
if(s->top==-1)
return false;
e=s->date[s->top--];
return true;
}
int main()
{ int i;
zhan *s;
initzhan(s);
for(i=0;i<Max;i++){
int x;
cin>>x;
push(s,x);
}
while(!judge(s)){
int x;
pop(s,x);
cout<<x<<endl;
}
return 0;
}