diff --git a/Project2.vcxproj b/Project2.vcxproj
index 6248ffa..79156a2 100644
--- a/Project2.vcxproj
+++ b/Project2.vcxproj
@@ -19,12 +19,14 @@
+
+
diff --git a/Project2.vcxproj.filters b/Project2.vcxproj.filters
index 4622cd9..c70b33b 100644
--- a/Project2.vcxproj.filters
+++ b/Project2.vcxproj.filters
@@ -27,6 +27,9 @@
源文件
+
+ 源文件
+
@@ -38,5 +41,8 @@
头文件
+
+ 头文件
+
\ No newline at end of file
diff --git a/Project2/Debug/Project2.Build.CppClean.log b/Project2/Debug/Project2.Build.CppClean.log
index 0ace058..2f60bb0 100644
--- a/Project2/Debug/Project2.Build.CppClean.log
+++ b/Project2/Debug/Project2.Build.CppClean.log
@@ -4,6 +4,7 @@ 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
diff --git a/Project2/Debug/Project2.log b/Project2/Debug/Project2.log
index f7f75f8..eafe481 100644
--- a/Project2/Debug/Project2.log
+++ b/Project2/Debug/Project2.log
@@ -1,9 +1,3 @@
- linked_list_stack.c
- 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”: 不是所有的控件路径都返回值
+ array_stack.c
+C:\code\lencode\Project2\array_stack.c(13,5): warning C4013: “memset”未定义;假设外部返回 int
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 d6b583e..f35c952 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 a48189b..2d1da44 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 6dfaeb0..9a03e9e 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 f9da5c0..86bcd1f 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_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
C:\code\lencode\Project2\main.c;C:\code\lencode\Project2\Project2\Debug\main.obj
diff --git a/Project2/Debug/Project2.tlog/link.command.1.tlog b/Project2/Debug/Project2.tlog/link.command.1.tlog
index 71d5a57..6848040 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 4b35156..eeb33b4 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 578ed71..1eb78f1 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\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_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 67bcf27..76fb829 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_stack.c b/array_stack.c
new file mode 100644
index 0000000..72e00ce
--- /dev/null
+++ b/array_stack.c
@@ -0,0 +1,58 @@
+#include
+#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");
+ return NULL;
+ }
+ memset(new_stack, 0, sizeof(array_stack));
+ new_stack->top = -1;
+ return new_stack;
+}
+
+// ջ
+void push_array_stack(array_stack* stack, elem_type value)
+{
+ if (stack->top + 1 > MAX_S)
+ {
+ printf("ջ[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");
+ return -1;
+ }
+ int value = stack->data[stack->top];
+ stack->top--;
+ return value;
+}
+
+// ӡջ
+void print_array_stack(array_stack* stack)
+{
+ if (stack->top == -1)
+ {
+ printf("ջΪ[print_array_stack()]\n");
+ return;
+ }
+ printf("ջԪ: %d\n", stack->data[stack->top]);
+ printf("-----\n");
+ for (int i = stack->top; i >= 0; i--)
+ {
+ printf("| %d |\n", stack->data[i]);
+ }
+ printf("-----\n");
+}
\ No newline at end of file
diff --git a/array_stack.h b/array_stack.h
new file mode 100644
index 0000000..a7eee27
--- /dev/null
+++ b/array_stack.h
@@ -0,0 +1,22 @@
+#ifndef ARRAY_SATCK
+#define ARRAY_SATCK
+#define MAX_S 100
+#define elem_type int
+typedef struct array_stack
+{
+ elem_type data[MAX_S];
+ int top;
+}array_stack;
+// ʼջ
+array_stack* init_array_stack(void);
+
+// ջ
+void push_array_stack(array_stack* s, elem_type value);
+
+// ջ
+int pop_array_stack(array_stack* s);
+
+// ӡջ
+void print_array_stack(array_stack* s);
+
+#endif
diff --git a/linked_list_stack.c b/linked_list_stack.c
index d1e8e90..283a999 100644
--- a/linked_list_stack.c
+++ b/linked_list_stack.c
@@ -6,6 +6,11 @@
stack_linked* init_stack_linked(void)
{
stack_linked* s = (stack_linked*)malloc(sizeof(stack_linked));
+ if (s == NULL)
+ {
+ printf("ڴʧܣ\n");
+ return NULL;
+ }
s->top = NULL;
s->size = 0;
return s;
@@ -15,6 +20,11 @@ stack_linked* init_stack_linked(void)
void push_stack_linked(stack_linked* s, elem_type value)
{
stack_node* node = (stack_node*)malloc(sizeof(stack_node));
+ if (node == NULL)
+ {
+ printf("ڴʧܣ\n");
+ return NULL;
+ }
node->value = value;
node->next = s->top;
s->top = node;
diff --git a/main.c b/main.c
index e0e8a3c..32def12 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include
#include
#include
+#include "array_stack.h"
#include "sq_list.h"
int main(void)
@@ -8,23 +9,31 @@ int main(void)
- sq_list* L = init_sq_list();
- sq_list* N = init_sq_list();
- for (int i = 1; i <= 3; i++)
- {
- N->data[i - 1] = i+10;
- }
- for (int i = 1; i <= 10; i++)
- {
- L->data[i - 1] = i;
- }
- N->length = 3;
- L->length = 10;
- print_sq_list(N);
- print_sq_list(L);
- mer_ge_sq_list(L,N);
- print_sq_list(L);
- printf("L->length:[%d]\n", L->length);
+ //sq_list* L = init_sq_list();
+ //sq_list* N = init_sq_list();
+ //for (int i = 1; i <= 3; i++)
+ //{
+ // N->data[i - 1] = i+10;
+ //}
+ //for (int i = 1; i <= 10; i++)
+ //{
+ // L->data[i - 1] = i;
+ //}
+ //N->length = 3;
+ //L->length = 10;
+ //print_sq_list(N);
+ //print_sq_list(L);
+ //mer_ge_sq_list(L,N);
+ //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);
printf("Hello World!\n");
system("pause");
return 0;