#include <stdio.h>
#include <process.h>
#include <malloc.h>
#include <string.h>
//------------------------函数结果状态代码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define TNFEASIBLE -1
#define OVERFLOW -2
//Status 是函数的类型,其值是函数结果状态代码
typedef int Status;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define MONEY 5
typedef struct ElemType {
char a[3];
int num;
int time;
}ElemType;
typedef struct SqStack {
ElemType *base;//在栈构造之前和销毁之后, base的值为NULL
ElemType *top;//栈顶指针
int stacksize;//当前已经分配的存储空间,以元素为单位
}SqStack;//栈的表示
typedef struct QNode {
ElemType data;
struct QNode *next;
}QNode, *QueuePtr;//队列的表示
typedef struct LinkQueue {
QueuePtr front;//队头指针
QueuePtr rear;//队尾指针
}LinkQueue;
//-----------------基本操作的实现
//-----------------栈
void InitStack(SqStack *S) {//构造一个空栈
S->base = (ElemType *)malloc(STACK_INIT_SIZE * sizeof(ElemType));
if (!S->base) exit(OVERFLOW);
S->top = S->base;
S->stacksize = STACK_INIT_SIZE;
//return OK;
}//InitStack
Status Push(SqStack *S, ElemType e) {//插入元素e为新的栈顶元素
if (S->top - S->base >= S->stacksize) {//栈满,追加存储空间
S->base = (ElemType *)realloc(S->base, (S->stacksize + STACKINCREMENT) * sizeof(ElemType));
if (!S->base) exit(OVERFLOW);//存储分配失败
S->top = S->base + S->stacksize;
S->stacksize += STACK_INIT_SIZE;
}
*S->top++ = e;
return OK;