#include <stdio.h> #include <stdlib.h> const int MAXSIZE = 100;//注意 #define ElementType int typedef struct SNode *Stack; struct SNode{ ElementType Data[MAXSIZE]; int Last; }; Stack CreateStack(int MAXSIZE); int IsFull(Stack S); void Push(Stack S,ElementType item); int IsEmpty(Stack S); ElementType Pop(Stack S); int main(){ Stack S = CreateStack(MAXSIZE); for(int i=0;i<11;i++) Push(S,i); while(!IsEmpty(S)){ printf("%d ",Pop(S)); } return 0; } Stack CreateStack(int MAXSIZE){ Stack S = (Stack)malloc(sizeof(SNode)); S->Last = -1; return S; } int IsFull(Stack S){ return S->Last+1 ==MAXSIZE; } int IsEmpty(Stack S){ return S->Last < 0; } void Push(Stack S, ElementType item){ if(IsFull(S)){ printf("栈满 "); return; }else{ S->Data[++S->Last]= item; return; } } ElementType Pop(Stack S){ if(IsEmpty(S)){ printf("栈为空 "); return NULL; }else{ return S->Data[S->Last--]; } }