用C++建立一个顺序栈并且包括(进栈,退栈和读栈顶)

来源:百度知道 编辑:UC知道 时间:2024/09/24 14:05:07
看好题在回答啊.答非所问!郁闷!

以前做的
参考一下吧

#include<iostream.h>
#include<malloc.h>
#include<conio.h>

#define ERROR 0
#define TRUE 1
#define FALSE 0
#define OK 1

#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10

typedef int Status ;
typedef int ElemType;

struct STACK
{
ElemType *base;
ElemType *top;
int stacksize;
};

typedef struct STACK SqStack;
//typedef struct STACK *pSqstack;
//函数声明
Status InitStack(SqStack &S);
void DestroyStack(SqStack &S);
void ClearStack(SqStack &S);
Status StackEmpty(SqStack S);
int StackLength(SqStack S);
Status GetTop(SqStack S,ElemType &e);
Status Push(SqStack &S,ElemType e);
Status Pop(SqStack &S,ElemType &e);
//初始化
Status InitStack(SqStack &S)
{
S.base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!S.base) return ERROR;
S.top=S.bas