基于链表的栈
使用链表实现了栈的基本功能 初始 入栈 出栈 Co-Authored-By: Jdhggg <111557398+Jdhggg@users.noreply.github.com>
This commit is contained in:
parent
d6d09e7423
commit
0fa5f049ab
@ -20,11 +20,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="linked_list.c" />
|
<ClCompile Include="linked_list.c" />
|
||||||
|
<ClCompile Include="linked_list_stack.c" />
|
||||||
<ClCompile Include="main.c" />
|
<ClCompile Include="main.c" />
|
||||||
<ClCompile Include="sq_list.c" />
|
<ClCompile Include="sq_list.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="linked_list.h" />
|
<ClInclude Include="linked_list.h" />
|
||||||
|
<ClInclude Include="linked_list_stack.h" />
|
||||||
<ClInclude Include="sq_list.h" />
|
<ClInclude Include="sq_list.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
<ClCompile Include="linked_list.c">
|
<ClCompile Include="linked_list.c">
|
||||||
<Filter>源文件</Filter>
|
<Filter>源文件</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="linked_list_stack.c">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="sq_list.h">
|
<ClInclude Include="sq_list.h">
|
||||||
@ -32,5 +35,8 @@
|
|||||||
<ClInclude Include="linked_list.h">
|
<ClInclude Include="linked_list.h">
|
||||||
<Filter>头文件</Filter>
|
<Filter>头文件</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="linked_list_stack.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,5 +1,2 @@
|
|||||||
main.c
|
linked_list_stack.c
|
||||||
sq_list.c
|
|
||||||
正在生成代码...
|
|
||||||
C:\code\lencode\Project2\sq_list.c(10,1): warning C4716: “init_sq_list”: 必须返回一个值
|
|
||||||
Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe
|
Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,4 @@
|
|||||||
C:\code\lencode\Project2\linked_list.c;C:\code\lencode\Project2\Project2\Debug\linked_list.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
|
C:\code\lencode\Project2\main.c;C:\code\lencode\Project2\Project2\Debug\main.obj
|
||||||
C:\code\lencode\Project2\sq_list.c;C:\code\lencode\Project2\Project2\Debug\sq_list.obj
|
C:\code\lencode\Project2\sq_list.c;C:\code\lencode\Project2\Project2\Debug\sq_list.obj
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@
|
|||||||
^C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\LINKED_LIST.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\MAIN.OBJ|C:\CODE\LENCODE\PROJECT2\PROJECT2\DEBUG\SQ_LIST.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
|
C:\code\lencode\Project2\Project2\Debug\Project2.ilk
|
||||||
|
Binary file not shown.
@ -0,0 +1,34 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#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;
|
||||||
|
}
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user