#include <stdio.h>
#include <stdlib.h>
#define ElementType int
//數據結構部分定義
typedef struct SNode *Stack;
typedef struct SNode{
ElementType Data;
Stack Next;
};
Stack InitStack(){
Stack S = (Stack)malloc(sizeof(struct SNode));
S->Next=NULL;
return S;
}
bool Push(Stack &S, ElementType item){
Stack T = (Stack)malloc(sizeof(struct SNode));
T->Next = S->Next;
T->Data=item;
S->Next=T;
return true;
}
ElementType Pop(Stack &S){
if(S->Next==NULL){
printf("棧為空\n");
return NULL;
}
Stack Tmp = S->Next;
ElementType X = Tmp->Data;
S->Next = Tmp->Next;
free(Tmp);
return X;
}
int main(){
Stack S = InitStack();
for(int i = 0; i<11;i++){
Push(S,i);
}
printf("%d\n",Pop(S));
printf("%d\n",Pop(S));
printf("%d\n",Pop(S));
return 0;
}