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 f35c952..d02a696 100644
Binary files a/Project2/Debug/Project2.tlog/CL.command.1.tlog and b/Project2/Debug/Project2.tlog/CL.command.1.tlog differ
diff --git a/Project2/Debug/Project2.tlog/CL.read.1.tlog b/Project2/Debug/Project2.tlog/CL.read.1.tlog
index 2d1da44..a215697 100644
Binary files a/Project2/Debug/Project2.tlog/CL.read.1.tlog and b/Project2/Debug/Project2.tlog/CL.read.1.tlog differ
diff --git a/Project2/Debug/Project2.tlog/CL.write.1.tlog b/Project2/Debug/Project2.tlog/CL.write.1.tlog
index 9a03e9e..864d760 100644
Binary files a/Project2/Debug/Project2.tlog/CL.write.1.tlog and b/Project2/Debug/Project2.tlog/CL.write.1.tlog differ
diff --git a/Project2/Debug/Project2.tlog/Cl.items.tlog b/Project2/Debug/Project2.tlog/Cl.items.tlog
index 86bcd1f..38e0c90 100644
--- a/Project2/Debug/Project2.tlog/Cl.items.tlog
+++ b/Project2/Debug/Project2.tlog/Cl.items.tlog
@@ -1,3 +1,4 @@
+C:\code\lencode\Project2\array_queue.c;C:\code\lencode\Project2\Project2\Debug\array_queue.obj
C:\code\lencode\Project2\array_stack.c;C:\code\lencode\Project2\Project2\Debug\array_stack.obj
C:\code\lencode\Project2\linked_list.c;C:\code\lencode\Project2\Project2\Debug\linked_list.obj
C:\code\lencode\Project2\linked_list_stack.c;C:\code\lencode\Project2\Project2\Debug\linked_list_stack.obj
diff --git a/Project2/Debug/Project2.tlog/link.command.1.tlog b/Project2/Debug/Project2.tlog/link.command.1.tlog
index 6848040..c25822a 100644
Binary files a/Project2/Debug/Project2.tlog/link.command.1.tlog and b/Project2/Debug/Project2.tlog/link.command.1.tlog differ
diff --git a/Project2/Debug/Project2.tlog/link.read.1.tlog b/Project2/Debug/Project2.tlog/link.read.1.tlog
index eeb33b4..97bf774 100644
Binary files a/Project2/Debug/Project2.tlog/link.read.1.tlog and b/Project2/Debug/Project2.tlog/link.read.1.tlog differ
diff --git a/Project2/Debug/Project2.tlog/link.secondary.1.tlog b/Project2/Debug/Project2.tlog/link.secondary.1.tlog
index 1eb78f1..3d021ab 100644
--- a/Project2/Debug/Project2.tlog/link.secondary.1.tlog
+++ b/Project2/Debug/Project2.tlog/link.secondary.1.tlog
@@ -1,2 +1,2 @@
-^C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\ARRAY_STACK.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\LINKED_LIST.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\LINKED_LIST_STACK.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\MAIN.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\SQ_LIST.OBJ
+^C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\ARRAY_QUEUE.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\ARRAY_STACK.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\LINKED_LIST.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\LINKED_LIST_STACK.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\MAIN.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\SQ_LIST.OBJ
C:\code\lencode\Project2\Project2\Debug\Project2.ilk
diff --git a/Project2/Debug/Project2.tlog/link.write.1.tlog b/Project2/Debug/Project2.tlog/link.write.1.tlog
index 76fb829..b07d1d1 100644
Binary files a/Project2/Debug/Project2.tlog/link.write.1.tlog and b/Project2/Debug/Project2.tlog/link.write.1.tlog differ
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;