栈(顺序存储)
typedef int Position;
struct SNode{
ElemType *data; //存储元素的数组
Postion top; //栈顶指针
int max; //最大容量
};
typedef struct SNode *Stack;
Stack CerateStack(int max){
Stack s=(Stcak)malloc(sizeof(struct SNode));
s->data=(ElemType *)malloc(max*sizeof(ElemType));
s->top=-1;
s->max=max;
return s;
}
boolean isFull(Stack s){
return (s->top==s->max-1);
}
booelan push(Stack s,ElemType e){
if(isFull()){
printf("栈满");
return false;
}
else {
s->data[++(s->top)]=e;
return true;
}
}
boolean isEmpty(){
return s->top==-1;
}
ElemType pop(Stack s){
if(isEmpty()){
printf("栈空");
return ERROR;
}
else
return (s->data[(s->top)--];
}
526

被折叠的 条评论
为什么被折叠?



