C语言实现线性表栈
C语言实现线性表栈
//栈--线性表实现
#define ERROR -1
typedef int Position;
typedef int ElemType;
struct SNode{
ElemType *Data;
Position Top;
int MaxSize;
};
typedef struct SNode *Stack;
Stack CreateStack(int MaxSize){
Stack S = (Stack)malloc(sizeof(struct SNode));
S->Data = (ElemType *)malloc(MaxSize * sizeof(ElementType));
S->Top = -1;
S->MaxSize = MaxSize;
return S;
}
void DestroyStack(Stack S){
if(S == NULL){
return;
}
if(S->Data != NULL){
free(S->Data);
}
free(S);
}
int IsEmpty(Stack S){
return (S->Top == -1);
}
int IsFull(Stack S){
return (S->Top == MaxSize);
}
int Push( Stack S, ElemType data){
if(IsFull(S)){
return 0;
}
S->Data[++(S->Top)] = data;
return 1;
}
ElemType Pop( Stack S){
if(IsEmpty()){
return ERROR;
}
return (S->Data[S->Top--]);
} 相关推荐
拉斯厄尔高福 2020-11-04
嵌入式资讯精选 2020-10-15
zhaochen00 2020-10-13
penkgao 2020-10-13
wanshiyingg 2020-09-29
Mars的自语 2020-09-27
shenwenjie 2020-09-24
一个逗逗 2020-09-22
flycony 2020-09-13
zhaochen00 2020-08-20
Biao 2020-08-20
qingsongzdq 2020-08-19
penkgao 2020-08-17
cetrolchen 2020-08-14
GuoSir 2020-08-07