#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int SElemType;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &s)
{
s.base =(SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
if(!s.base ) exit (OVERFLOW);
s.top =s.base;
s.stacksize =STACK_INIT_SIZE;
return OK;
}
Status GetTop(SqStack s,SElemType &e)
{
if(s.top ==s.base ) return ERROR;
e=*(s.top -1);
return OK;
}
Status Push(SqStack &s,SElemType e)
{
if(s.top -s.base >=s.stacksize )
{
s.base =(SElemType *)realloc(s.base ,s.stacksize +STACKINCREMENT*sizeof(SElemType));
if(!s.base )exit (OVERFLOW);
s.top =s.base +s.stacksize ;
s.stacksize +=STACKINCREMENT;
}
*s.top ++=e;
return OK;
}
Status Pop(SqStack &s,SElemType &e)
{
if(s.top ==s.base )return ERROR;
e=*--s.top ;
return OK;
}
int main()
{
int n;
SqStack Sa;
InitStack(Sa);
while(~scanf("%d",&n))
{
Push(Sa,n);
}
int e;
GetTop(Sa,e);
printf("栈顶==%d\n",e);
Pop(Sa,e);
printf("删除栈顶==%d\n",e);
GetTop(Sa,e);
printf("此时栈顶==%d\n",e);
int *q;
for(q=Sa.top-1;q>=Sa.base;q--)
{
printf("%d\n",*q);
}
return 0;
}