#include <iostream>
using namespace std;
#include <stdio.h>
#include<stdlib.h>
#define N 1000
//创建顺序栈
typedef struct{
int data[100];
int top;
}sqstack;
//初始化顺序栈
void initsqstack(sqstack &s){
s.top=0;
}
//入栈
void push(sqstack &s,int e){
if(s.top>=N) return; //若栈满,返回
s.data[s.top++]=e;
}
//出栈
int pop(sqstack &s){
if(s.top==0) return -1; //若栈为空,返回-1
return s.data[--s.top];
}
//取栈顶元素
int gettop(sqstack &s){
if(s.top==0) return -1;
else return s.data[s.top-1];
}
//判断栈是否为空
int emptystack(sqstack &s){
if(s.top==0) return 1;
else return 0;
}
void output(sqstack &s){
for(int i=0;i<s.top;i++){
cout << s.data[i]<<" ";
}
cout << endl;
}
int main()
{
sqstack s;
int n=6;
initsqstack(s);
for(int i=1;i<=5;i++){
push(s,i);
}
output(s);
cout <<"出栈: "<<pop(s)<<endl;
cout <<"获得栈顶元素: "<<gettop(s)<<endl;
while(n!=10){
push(s,n++);
}
output(s);
pop(s);
output(s);
return 0;
}