Skip to content

Commit 7dcd69e

Browse files
committed
添加Stack
栈链相关 了解用
1 parent e3726b3 commit 7dcd69e

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed

Stack/Stack.cbp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="Stack" />
6+
<Option pch_mode="2" />
7+
<Option compiler="gcc" />
8+
<Build>
9+
<Target title="Debug">
10+
<Option output="bin/Debug/Stack" prefix_auto="1" extension_auto="1" />
11+
<Option object_output="obj/Debug/" />
12+
<Option type="1" />
13+
<Option compiler="gcc" />
14+
<Compiler>
15+
<Add option="-g" />
16+
</Compiler>
17+
</Target>
18+
<Target title="Release">
19+
<Option output="bin/Release/Stack" prefix_auto="1" extension_auto="1" />
20+
<Option object_output="obj/Release/" />
21+
<Option type="1" />
22+
<Option compiler="gcc" />
23+
<Compiler>
24+
<Add option="-O2" />
25+
</Compiler>
26+
<Linker>
27+
<Add option="-s" />
28+
</Linker>
29+
</Target>
30+
</Build>
31+
<Compiler>
32+
<Add option="-Wall" />
33+
</Compiler>
34+
<Unit filename="main.c">
35+
<Option compilerVar="CC" />
36+
</Unit>
37+
<Extensions>
38+
<code_completion />
39+
<envvars />
40+
<debugger />
41+
<lib_finder disable_auto="1" />
42+
</Extensions>
43+
</Project>
44+
</CodeBlocks_project_file>

Stack/Stack.depend

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# depslib dependency file v1.0
2+
1401889938 source:d:\allprojects\c\stack\main.c
3+
<stdio.h>
4+
<stdlib.h>
5+

Stack/Stack.layout

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_layout_file>
3+
<ActiveTarget name="Debug" />
4+
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
5+
<Cursor>
6+
<Cursor1 position="1051" topLine="59" />
7+
</Cursor>
8+
</File>
9+
</CodeBlocks_layout_file>

Stack/bin/Debug/Stack.exe

28.6 KB
Binary file not shown.

Stack/main.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#define OK 1
5+
#define FALSE 0
6+
#define TRUE 1
7+
#define ERROR 0
8+
9+
typedef int ElemType;
10+
typedef int status;
11+
12+
typedef struct StackNode
13+
{
14+
ElemType data;
15+
struct StackNode *next;
16+
}StackNode, *LinkStackPtr;
17+
18+
typedef struct
19+
{
20+
LinkStackPtr top;
21+
int counter;
22+
}LinkStack;
23+
24+
void initLinkStack( LinkStack **s )
25+
{
26+
(*s) = (LinkStack *)malloc(sizeof(LinkStack));
27+
28+
(*s)->counter = 0;
29+
(*s)->top = NULL;
30+
31+
return;
32+
}
33+
34+
status push( LinkStack *s, ElemType e )
35+
{
36+
LinkStackPtr p = (LinkStackPtr)malloc(sizeof(StackNode));
37+
38+
p->data = e;
39+
p->next = s->top;
40+
s->top = p;
41+
s->counter++;
42+
43+
return OK;
44+
}
45+
46+
status pop( LinkStack *s, ElemType *e )
47+
{
48+
if( s->top == NULL )
49+
{
50+
return ERROR;
51+
}
52+
53+
LinkStackPtr p = s->top;
54+
55+
*e = p->data;
56+
57+
s->top = p->next;
58+
s->counter--;
59+
60+
free(p);
61+
62+
return OK;
63+
}
64+
65+
int main()
66+
{
67+
LinkStack *s = NULL;
68+
69+
ElemType e;
70+
71+
initLinkStack( &s );
72+
73+
push( s, 23 );
74+
75+
pop( s, &e );
76+
77+
printf("%d", e);
78+
79+
return 0;
80+
}

Stack/obj/Debug/main.o

3.34 KB
Binary file not shown.

0 commit comments

Comments
 (0)