From 0fa5f049ab4e291479bceb9bb50082c04b5d630f Mon Sep 17 00:00:00 2001
From: Jdhggg <24016020834@stu.nsu.edu.cn>
Date: Tue, 18 Mar 2025 17:30:39 +0800
Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8E=E9=93=BE=E8=A1=A8=E7=9A=84?=
=?UTF-8?q?=E6=A0=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
使用链表实现了栈的基本功能
初始
入栈
出栈
Co-Authored-By: Jdhggg <111557398+Jdhggg@users.noreply.github.com>
---
Project2.vcxproj | 2 +
Project2.vcxproj.filters | 6 +++
Project2/Debug/Project2.log | 5 +-
.../Debug/Project2.tlog/CL.command.1.tlog | Bin 2190 -> 2958 bytes
Project2/Debug/Project2.tlog/CL.read.1.tlog | Bin 10262 -> 13388 bytes
Project2/Debug/Project2.tlog/CL.write.1.tlog | Bin 2036 -> 3048 bytes
Project2/Debug/Project2.tlog/Cl.items.tlog | 1 +
.../Debug/Project2.tlog/link.command.1.tlog | Bin 1490 -> 1690 bytes
Project2/Debug/Project2.tlog/link.read.1.tlog | Bin 3500 -> 4106 bytes
.../Debug/Project2.tlog/link.secondary.1.tlog | 2 +-
.../Debug/Project2.tlog/link.write.1.tlog | Bin 500 -> 624 bytes
linked_list_stack.c | 34 ++++++++++++++
linked_list_stack.h | 44 +++++++++++++++++-
13 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/Project2.vcxproj b/Project2.vcxproj
index 0456f2b..6248ffa 100644
--- a/Project2.vcxproj
+++ b/Project2.vcxproj
@@ -20,11 +20,13 @@
+
+
diff --git a/Project2.vcxproj.filters b/Project2.vcxproj.filters
index cb26a7d..b947b58 100644
--- a/Project2.vcxproj.filters
+++ b/Project2.vcxproj.filters
@@ -24,6 +24,9 @@
源文件
+
+ 源文件
+
@@ -32,5 +35,8 @@
头文件
+
+ 头文件
+
\ No newline at end of file
diff --git a/Project2/Debug/Project2.log b/Project2/Debug/Project2.log
index c2e2e7b..6bc09b0 100644
--- a/Project2/Debug/Project2.log
+++ b/Project2/Debug/Project2.log
@@ -1,5 +1,2 @@
- main.c
- sq_list.c
- 正在生成代码...
-C:\code\lencode\Project2\sq_list.c(10,1): warning C4716: “init_sq_list”: 必须返回一个值
+ linked_list_stack.c
Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe
diff --git a/Project2/Debug/Project2.tlog/CL.command.1.tlog b/Project2/Debug/Project2.tlog/CL.command.1.tlog
index 9ca4aac48986ba7ddbb4b63363ce9a305b2317ae..6a4fb38973b6767878c73c669a1d7a49183bcb7a 100644
GIT binary patch
delta 57
zcmeAZ>=WN0$GrI!>k_8Lub7x8pJ5W?j%NsF2w`w!aAxq{=slfD1c}d}2NdOH;9>v(
DQlEGye~>hpq#-cTk7x25v6{^jcoKL4%FbYhLW3vGOOlt
+#include
+#include "linked_list_stack.h"
+
+// ʼջ
+stack_linked* init_stack_linked(void)
+{
+ stack_linked* s = (stack_linked*)malloc(sizeof(stack_linked));
+ s->top = NULL;
+ s->size = 0;
+ return s;
+}
+
+// ջ
+void push_stack_linked(stack_linked* s, int value)
+{
+ stack_node* node = (stack_node*)malloc(sizeof(stack_node));
+ node->value = value;
+ node->next = s->top;
+ s->top = node;
+ s->size++;
+}
+
+// ջ
+int pop_stack_linked(stack_linked* s)
+{
+ int flog = 0;
+ flog = s->top->value;
+ stack_node* tmp = s->top;
+ s->top = s->top->next;
+ free(tmp);
+ tmp = NULL;
+ return flog;
+}
\ No newline at end of file
diff --git a/linked_list_stack.h b/linked_list_stack.h
index 6f70f09..dc7bea1 100644
--- a/linked_list_stack.h
+++ b/linked_list_stack.h
@@ -1 +1,43 @@
-#pragma once
+#ifndef LINKED_LIST_STACK_H
+#define LINKED_LIST_STACK_H
+
+typedef struct stack_node
+{
+ int value;
+ struct stack_node *next;
+
+}stack_node;
+
+typedef struct stack_linked
+{
+ stack_node *top;
+ int size;
+}stack_linked;
+
+// ʼջ
+stack_linked* init_stack_linked(void);
+
+// ջ
+void push_stack_linked(stack_linked* s, int value);
+
+// ջ
+int pop_stack_linked(stack_linked* s);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif