#include <stdio.h>
#include <iostream>
#include <malloc.h>
using namespace std;
typedef char ElemType;
#define MAXSIZE 50
typedef struct
{
ElemType data[MAXSIZE];
int top;
}SqStack;
void InitStack(SqStack *&S)
{
S=(SqStack*)malloc(sizeof(SqStack));
S->top=0;
}
void DestroyStack(SqStack *&S)
{
free(S);
}
bool StackFull(SqStack *S)
{
if(S->top==MAXSIZE) return true;
else return false;
}
bool StackEmpty(SqStack *S)
{
if(S->top==MAXSIZE)
return true;
else false;
}
bool Push(SqStack *&S,ElemType e)
{
if(S->top==MAXSIZE)
return false;
S->data[S->top]=e;
S->top++;
return true;
}
bool Pop(SqStack *&S,ElemType &e)
{
if(S->top==0)
return false;
S->top--;
e=S->data[S->top];
return true;
}
bool GetTop(SqStack *&S,ElemType &e)
{
if(S->top==0)
return false;
e=S->data[S->top-1];
return true;
}
onemoo
相关分类