From c62b93a09ae1cde58df4f983407827e433cb5a50 Mon Sep 17 00:00:00 2001 From: ViolentAyang <76544389+ViolentAyang@users.noreply.github.com> Date: Sun, 20 Mar 2022 14:40:12 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E9=93=BE=E6=A0=88=E7=9A=84=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E6=93=8D=E4=BD=9C.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 栈/链栈的基本操作.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 栈/链栈的基本操作.c 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; +}