diff --git a/栈/链栈的基本操作.c b/栈/链栈的基本操作.c new file mode 100644 index 0000000..2e7e23e --- /dev/null +++ b/栈/链栈的基本操作.c @@ -0,0 +1,45 @@ +#include +#include +#include +#define MaxSize 10 + +typedef struct Linknode{ + int data; + struct Linknode *next; +}LiNode,*LiStack; + +//初始化 +bool InitLiStack(LiStack L){ + L = (LiStack)malloc(sizeof(LiNode)); + L->next = NULL; + return true; +} +//入栈 +void Push(LiStack L,int x){ + LiStack s = (LiStack)malloc(sizeof(LiNode)); + s->data = x; + s->next = L->next; + L->next = s; +} +//出栈 +void Pop(LiStack L,int x){ + LiNode *s = L->next; + x = s->data; + printf("弹出的元素为:%d\n",x); + L->next = s->next; + free(s); +} +int main(){ + LiNode L; + InitLiStack(&L); + Push(&L,1); + Push(&L,3); + Push(&L,4); + Push(&L,5); + Push(&L,6); + Pop(&L,-1); + Pop(&L,-1); + Pop(&L,-1); + Pop(&L,-1); + return 0; +}