更新
This commit is contained in:
parent
6c6a3c78aa
commit
60b1d8e65a
@ -19,10 +19,12 @@
|
|||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="linked_list.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="sq_list.h" />
|
<ClInclude Include="sq_list.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
|
@ -21,10 +21,16 @@
|
|||||||
<ClCompile Include="sq_list.c">
|
<ClCompile Include="sq_list.c">
|
||||||
<Filter>源文件</Filter>
|
<Filter>源文件</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="linked_list.c">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="sq_list.h">
|
<ClInclude Include="sq_list.h">
|
||||||
<Filter>头文件</Filter>
|
<Filter>头文件</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="linked_list.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,3 @@
|
|||||||
|
C:\code\lencode\Project2\linked_list.c;C:\code\lencode\Project2\Project2\Debug\linked_list.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\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\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.
28
linked_list.c
Normal file
28
linked_list.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "linked_list.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 初始赋值
|
||||||
|
node* init_node(int val)
|
||||||
|
{
|
||||||
|
node* new_node = (node*)malloc(sizeof(node));
|
||||||
|
new_node->value = val;
|
||||||
|
new_node->next = NULL;
|
||||||
|
return new_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 删除下一个节点
|
||||||
|
void delete_node(node* n)
|
||||||
|
{
|
||||||
|
n->next = n->next->next;
|
||||||
|
free(n->next);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 替换节点值
|
||||||
|
void replace_node(node* n, int val)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
31
linked_list.h
Normal file
31
linked_list.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef LINKED_LIST_H
|
||||||
|
#define LINKED_LIST_H
|
||||||
|
|
||||||
|
typedef struct node
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
struct node* next;
|
||||||
|
} node;
|
||||||
|
|
||||||
|
// 初始化节点
|
||||||
|
node* init_node(int val);
|
||||||
|
|
||||||
|
// 删除下一个节点
|
||||||
|
void delete_node(node* n);
|
||||||
|
|
||||||
|
// 替换节点
|
||||||
|
void replace_node (node* n, int val);
|
||||||
|
|
||||||
|
// 插入节点
|
||||||
|
void insert_node(node** head, int val);
|
||||||
|
|
||||||
|
//访问节点
|
||||||
|
int get_node(node* n);
|
||||||
|
|
||||||
|
// 查找
|
||||||
|
int find_node(node* head, int val);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
5
main.c
5
main.c
@ -7,8 +7,11 @@ int main(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
sq_list *list = init_sq_list(&list);
|
sq_list *list = init_sq_list(&list);
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
list->data[i] = i;
|
||||||
|
}
|
||||||
list->length = 6;
|
list->length = 6;
|
||||||
replace_sq_list(list, 2, 5);
|
insert_sq_list(list, 3, 666);
|
||||||
print_sq_list(list);
|
print_sq_list(list);
|
||||||
printf("Hello World!\n");
|
printf("Hello World!\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user