From 1633ab47cbecd80de9cbccd9e2ebc18a3102be32 Mon Sep 17 00:00:00 2001
From: Jdhggg <24016020834@stu.nsu.edu.cn>
Date: Mon, 24 Mar 2025 09:37:44 +0800
Subject: [PATCH] =?UTF-8?q?=E9=98=9F=E5=88=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.vs/VSWorkspaceState.json | 6 ++
Project2.vcxproj | 2 +
Project2.vcxproj.filters | 6 ++
Project2/Debug/Project2.Build.CppClean.log | 18 ----
Project2/Debug/Project2.log | 26 +++++-
.../Debug/Project2.tlog/CL.command.1.tlog | Bin 3702 -> 4446 bytes
Project2/Debug/Project2.tlog/CL.read.1.tlog | Bin 15610 -> 17924 bytes
Project2/Debug/Project2.tlog/CL.write.1.tlog | Bin 2276 -> 2436 bytes
Project2/Debug/Project2.tlog/Cl.items.tlog | 1 +
.../Debug/Project2.tlog/link.command.1.tlog | Bin 1866 -> 2042 bytes
Project2/Debug/Project2.tlog/link.read.1.tlog | Bin 3976 -> 4558 bytes
.../Debug/Project2.tlog/link.secondary.1.tlog | 2 +-
.../Debug/Project2.tlog/link.write.1.tlog | Bin 736 -> 848 bytes
array_queue.c | 86 ++++++++++++++++++
array_queue.h | 34 +++++++
array_stack.c | 19 ++--
main.c | 19 +++-
17 files changed, 184 insertions(+), 35 deletions(-)
create mode 100644 .vs/VSWorkspaceState.json
create mode 100644 array_queue.c
create mode 100644 array_queue.h
diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json
new file mode 100644
index 0000000..6b61141
--- /dev/null
+++ b/.vs/VSWorkspaceState.json
@@ -0,0 +1,6 @@
+{
+ "ExpandedNodes": [
+ ""
+ ],
+ "PreviewInSolutionExplorer": false
+}
\ No newline at end of file
diff --git a/Project2.vcxproj b/Project2.vcxproj
index 79156a2..451a113 100644
--- a/Project2.vcxproj
+++ b/Project2.vcxproj
@@ -19,6 +19,7 @@
+
@@ -26,6 +27,7 @@
+
diff --git a/Project2.vcxproj.filters b/Project2.vcxproj.filters
index c70b33b..a28af6f 100644
--- a/Project2.vcxproj.filters
+++ b/Project2.vcxproj.filters
@@ -30,6 +30,9 @@
源文件
+
+ 源文件
+
@@ -44,5 +47,8 @@
头文件
+
+ 头文件
+
\ No newline at end of file
diff --git a/Project2/Debug/Project2.Build.CppClean.log b/Project2/Debug/Project2.Build.CppClean.log
index 2f60bb0..e69de29 100644
--- a/Project2/Debug/Project2.Build.CppClean.log
+++ b/Project2/Debug/Project2.Build.CppClean.log
@@ -1,18 +0,0 @@
-c:\code\lencode\project2\project2\debug\vc143.pdb
-c:\code\lencode\project2\project2\debug\vc143.idb
-c:\code\lencode\project2\project2\debug\sq_list.obj
-c:\code\lencode\project2\project2\debug\main.obj
-c:\code\lencode\project2\project2\debug\linked_list_stack.obj
-c:\code\lencode\project2\project2\debug\linked_list.obj
-c:\code\lencode\project2\project2\debug\array_stack.obj
-c:\code\lencode\project2\debug\project2.exe
-c:\code\lencode\project2\debug\project2.pdb
-c:\code\lencode\project2\project2\debug\project2.ilk
-c:\code\lencode\project2\project2\debug\project2.tlog\cl.command.1.tlog
-c:\code\lencode\project2\project2\debug\project2.tlog\cl.items.tlog
-c:\code\lencode\project2\project2\debug\project2.tlog\cl.read.1.tlog
-c:\code\lencode\project2\project2\debug\project2.tlog\cl.write.1.tlog
-c:\code\lencode\project2\project2\debug\project2.tlog\link.command.1.tlog
-c:\code\lencode\project2\project2\debug\project2.tlog\link.read.1.tlog
-c:\code\lencode\project2\project2\debug\project2.tlog\link.secondary.1.tlog
-c:\code\lencode\project2\project2\debug\project2.tlog\link.write.1.tlog
diff --git a/Project2/Debug/Project2.log b/Project2/Debug/Project2.log
index eafe481..7d68a59 100644
--- a/Project2/Debug/Project2.log
+++ b/Project2/Debug/Project2.log
@@ -1,3 +1,25 @@
- array_stack.c
-C:\code\lencode\Project2\array_stack.c(13,5): warning C4013: “memset”未定义;假设外部返回 int
+ array_queue.c
+ array_stack.c
+C:\code\lencode\Project2\array_queue.c(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
+C:\code\lencode\Project2\array_queue.h(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
+ (编译源文件“array_queue.c”)
+
+C:\code\lencode\Project2\array_queue.c(22,5): warning C4013: “memset”未定义;假设外部返回 int
+C:\code\lencode\Project2\array_stack.c(12,5): warning C4013: “memset”未定义;假设外部返回 int
+ linked_list.c
+ linked_list_stack.c
+C:\code\lencode\Project2\linked_list_stack.c(26,3): warning C4098: “push_stack_linked”:“void”函数返回值
+ main.c
+C:\code\lencode\Project2\array_queue.h(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
+ (编译源文件“main.c”)
+
+C:\code\lencode\Project2\main.c(37,22): warning C4013: “init_array_queue”未定义;假设外部返回 int
+C:\code\lencode\Project2\main.c(37,18): warning C4047: “初始化”:“array_queue *”与“int”的间接级别不同
+ sq_list.c
+C:\code\lencode\Project2\sq_list.c(102,9): warning C4033: “locate_list”必须返回值
+C:\code\lencode\Project2\sq_list.c(112,9): warning C4033: “locate_list”必须返回值
+C:\code\lencode\Project2\sq_list.c(166,34): warning C4047: “函数”:“int”与“sq_list *”的间接级别不同
+C:\code\lencode\Project2\sq_list.c(166,34): warning C4024: “locate_list”: 形参和实参 2 的类型不同
+ 正在生成代码...
+C:\code\lencode\Project2\sq_list.c(116,1): warning C4715: “locate_list”: 不是所有的控件路径都返回值
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 f35c9529884da54de0dc69df706d216455691b01..d02a696ac866d2792f760be0c048d72f8f8bea1f 100644
GIT binary patch
delta 60
zcmew+b5Ci4+2ja59?n39PzF~J-fYj@$b>31`5}`nP(*I?1MX=|lV34;ZS-;C1^@+w
B5sCl+
delta 20
ccmcbo^i5`h+2je_Vw+{yoVYi?VtT;@09Q>1$N&HU
diff --git a/Project2/Debug/Project2.tlog/CL.read.1.tlog b/Project2/Debug/Project2.tlog/CL.read.1.tlog
index 2d1da449c7629268d08747aa9d035e543eb736f4..a2156979a6fc6056cd2fca183b89ca4b8528026b 100644
GIT binary patch
delta 88
zcmexW+0w%}!EADlArEIDLnwnQ2yeb9vYK=91{({6&}4nX#LW*x=75B~CR-SqOwJJz
W+vsyZY4R!?I}~NMn;n#Y@B#qquN&6@
delta 300
zcmZ8d%?bfg7(F&(LKc#wDN7~E?_}p^7&T0}BSy3E8dfYUC3PRbn(b^of(NmZwJaRB
zq;wbOp6@&7bo#ct&~tTY$cLT|vc@?o_s!ym$d?%jF8VbiFM3Vh&18@>ZgEAHsf^rd
zF>i(;#^}Mp3<5p|u=($xO&nrDbcqf%KKBkLijS%L@g7X{shrZ|qC~9?A@hmTx}(y4
zSab^R<}lEp^NSUfQAdT7EHq)$
diff --git a/Project2/Debug/Project2.tlog/CL.write.1.tlog b/Project2/Debug/Project2.tlog/CL.write.1.tlog
index 9a03e9ef022cd6bf9dc445c03e95270b2f2c4cf8..864d760aca0450acb5759cfe636bb23998125f0d 100644
GIT binary patch
delta 92
zcmaDN*djc^i8GKPl))8*Cwf~>?qHYN7@)^8nTI6?Au+j-#StjOgCsJSJ%92qRuiCT
V3z*Jg6`NeemJOBUy
diff --git a/Project2/Debug/Project2.tlog/link.read.1.tlog b/Project2/Debug/Project2.tlog/link.read.1.tlog
index eeb33b4eada9725eb83808057ec575447a3b073d..97bf774dbd01ca6aa7d5911ac2f5236b54e68763 100644
GIT binary patch
delta 161
zcmeB>Kc_q)fisXHl))8*CuT-ZPT-Q89LE^6@yH5Jgv8{N+_9SzxSlai{=+1-c^=Oz
zrpXUD{8*hBJQ@5ZJF>|NM=)40m@&jK1Ti=>=m8CjU~rxMkx6y(Jf0R~uqvRO2ZKLD
fFhdAX4x$!DJ2Qj_JDOl!o~{?OaL1B1g`)9
diff --git a/array_queue.c b/array_queue.c
new file mode 100644
index 0000000..a91a531
--- /dev/null
+++ b/array_queue.c
@@ -0,0 +1,86 @@
+#include
+#include
+#include "array_queue.h"
+
+/*@-------------
+ # 设计思路更新(原版漏洞太多):
+ 设计圆环式队列,当rear == size时,循环到数组的[0]位,当然这样的队列仍然遵循`先进先出原则`
+ ## 实现思路:
+ 通过取模运算,使得rear和front都在数组的[0,size-1]范围内,这样就能实现循环队列的功能.
+ # 优点解析:
+ 在传统的队列中,当队尾到达队列的末尾时,即使队列前面还有空闲空间,也无法继续入队,导致空间浪费。而环形队列通过取模运算,\n
+ 使得队尾指针可以在到达队列末尾后,从头开始继续使用队列的空闲空间,从而提高了空间的利用率。
+@-------------*/
+
+
+// 初始化队列
+array_queue *init_array_queue()
+{
+ array_queue *q = (array_queue *)malloc(sizeof(array_queue));
+ if (q == NULL)
+ {printf("error: malloc failed[From init_queue]"); return NULL;}
+ memset(q,0,sizeof(array_queue));
+ q->front = 0;
+ q->rear = 0;
+ q->size = 0;
+ return q;
+}
+
+// 判空
+int empty_array_queue(array_queue *q)
+{
+ if (q->size == 0)
+ return 1;
+ else
+ return 0;
+}
+
+// 判断满
+int full_array_queue(array_queue *q)
+{
+ if (q->size == MAX_QUEUE)
+ return 1;
+ else
+ return 0;
+}
+
+// 入队
+void push_array_queue(array_queue *q, elem_type value)
+{
+ if (full_array_queue(q))
+ {printf("error: queue is full[From push_queue]"); return;}
+ q->data[q->rear] = value;
+ q->rear = (q->front + q->size + 1) % MAX_QUEUE;
+ q->size++;
+}
+
+// 出队
+elem_type pop_array_queue(array_queue *q)
+{
+ if (empty_array_queue(q))
+ {printf("error: queue is empty[From pop_queue]"); return -1;}
+ elem_type value = q->data[q->front];
+ q->front = (q->front + 1) % MAX_QUEUE;
+ q->size--;
+ return value;
+}
+
+// 打印队列
+void print_array_queue(array_queue *q)
+{
+ if (empty_array_queue(q))
+ {
+ printf("error :\n");
+ return ;
+ }
+ for (int i=q->front; i!=q->rear;i = (i+1)%MAX_QUEUE)
+ {
+ printf("[");
+ printf("%d ",q->data[i]);
+ printf("]\n");
+ }
+}
+
+
+
+// if while for void return fuck shit def sleep
\ No newline at end of file
diff --git a/array_queue.h b/array_queue.h
new file mode 100644
index 0000000..4f05aa0
--- /dev/null
+++ b/array_queue.h
@@ -0,0 +1,34 @@
+#ifndef ARRAY_QUEUE_H
+#define ARRAY_QUEUE_H
+#define MAX_QUEUE 3
+#define elem_type int
+// queue 构建
+typedef struct array_queue
+{
+ elem_type data[MAX_QUEUE];
+ int front; // 队列头指针
+ int rear; // 队列尾指针
+ int size;
+}array_queue;
+
+// queue 初始化
+array_queue *inti_array_queue();
+
+// 判空
+int empty_array_queue(array_queue *q);
+
+//判满
+int full_array_queue(array_queue *q);
+
+// 入队
+void push_array_queue(array_queue *q, elem_type value);
+
+// 出队
+elem_type pop_array_queue(array_queue *q);
+
+// 打印队列
+void print_array_queue(array_queue *q);
+
+
+
+#endif
\ No newline at end of file
diff --git a/array_stack.c b/array_stack.c
index 72e00ce..058a9a9 100644
--- a/array_stack.c
+++ b/array_stack.c
@@ -2,12 +2,11 @@
#include
#include "array_stack.h"
-// ʼջ
+// 初始化数组栈
array_stack* init_array_stack(void)
{
array_stack* new_stack = (array_stack*)malloc(sizeof(array_stack));
- if (new_stack == NULL) {
- printf("ڴʧ[init_array_stack()]\n");
+ if (new_stack == NULL) { printf("error: malloc() failed [From: init_array_stack()]\n");
return NULL;
}
memset(new_stack, 0, sizeof(array_stack));
@@ -15,24 +14,24 @@ array_stack* init_array_stack(void)
return new_stack;
}
-// ջ
+// 入栈
void push_array_stack(array_stack* stack, elem_type value)
{
if (stack->top + 1 > MAX_S)
{
- printf("ջ[push_array_stack()]\n");
+ printf("Stack overflow [From: push_array_stack()]\n");
return;
}
stack->top++;
stack->data[stack->top] = value;
}
-// ջ
+// 出栈
int pop_array_stack(array_stack* stack)
{
if (stack->top == -1)
{
- printf("ջΪ[pop_array_stack()]\n");
+ printf("Stack underflow [From: pop_array_stack()]\n");
return -1;
}
int value = stack->data[stack->top];
@@ -40,15 +39,15 @@ int pop_array_stack(array_stack* stack)
return value;
}
-// ӡջ
+// 打印
void print_array_stack(array_stack* stack)
{
if (stack->top == -1)
{
- printf("ջΪ[print_array_stack()]\n");
+ printf("viod stack [From: print_array_stack()]\n");
return;
}
- printf("ջԪ: %d\n", stack->data[stack->top]);
+ printf("top: %d\n", stack->data[stack->top]);
printf("-----\n");
for (int i = stack->top; i >= 0; i--)
{
diff --git a/main.c b/main.c
index 32def12..9d2db54 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,7 @@
#include
#include "array_stack.h"
#include "sq_list.h"
+#include "array_queue.h"
int main(void)
{
@@ -27,13 +28,23 @@ int main(void)
//print_sq_list(L);
//printf("L->length:[%d]\n", L->length);
-
- // ջ
+/*
+ // ջ����
array_stack* stack = init_array_stack();
push_array_stack(stack, 1);
push_array_stack(stack, 2);
- push_array_stack(stack, 3);
- print_array_stack(stack);
+ push_array_stack(stack, 3); */
+ array_queue *q = init_array_queue();
+ push_array_queue(q,0);
+ push_array_queue(q,1);
+ push_array_queue(q,2);
+ print_array_queue(q);
+ printf("---------------------\n");
+ pop_array_queue(q);
+ print_array_queue(q);
+ printf("----------\n");
+ push_array_queue(q, 666);
+ print_array_queue(q);
printf("Hello World!\n");
system("pause");
return 0;