#include<stdio.h>
#include<iostream.h>
#include<malloc.h>
#include<cstdlib>
#include<math.h>
#include<string>
#define MAXSIZE 100
#define OK 1
#define ERROR 0
typedef int Status;
typedef struct
{
char opera[30];
int data;
}ElemType;
typedef struct
{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S)
{
S.base=(ElemType *)malloc(MAXSIZE*sizeof(ElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base;
S.stacksize=MAXSIZE;
return OK;
}
Status Push(SqStack &S,ElemType &e)
{
if(S.top-S.base==S.stacksize) return ERROR;
*S.top++=e;
return OK;
}
Status Pop(SqStack &S,ElemType &e)
{
if(S.top==S.base) return ERROR;
e=*--S.top;
return OK;
}
ElemType GetTop(SqStack S)
{
if(S.base!=S.top) return *(S.top-1);
}
Status EnterData(SqStack &S)
{
cout<<"かずくれね?"<<endl;
int length=0;
cin>>length;
cout<<"number,opera"<<endl;
for(int i=0;i<length;i++)
{
ElemType e;
cin>>e.data>>e.opera;
Push(S,e);
}
return OK;
}
void StackTraverse(SqStack S)
{
ElemType e;
int length=0;
while(S.base!=S.top)
{
e=GetTop(S);
cout<<e.data<<e.opera<<endl;
--S.top;
length++;
}
cout<<"总计"<<length<<endl;
}
Status DestroyStack(SqStack &S)
{
free(S.base);
S.base = NULL;
S.top = NULL;
S.stacksize = 0;
return OK;
}
void main()
{
SqStack S;
InitStack(S);
EnterData(S);
cout<<"希望成功录入数据..."<<endl;
StackTraverse(S);
cout<<"执行销毁"<<DestroyStack(S)<<endl;
system("pause");
}