From 0786182c5803233569775486743694dac0f7bb74 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 13:15:02 +0800 Subject: [PATCH 01/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9cmake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/yonglin_zhang/CMakeLists.txt b/yonglin_zhang/CMakeLists.txt index e69de29..e0c5cad 100644 --- a/yonglin_zhang/CMakeLists.txt +++ b/yonglin_zhang/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(C) \ No newline at end of file -- Gitee From 9b2ea8128c748c2a7f3e7d622139036064ae1f21 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 13:24:14 +0800 Subject: [PATCH 02/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/CMakeLists.txt | 1 + yonglin_zhang/C/link_list/CMakeLists.txt | 0 yonglin_zhang/C/link_list/include/link_list.h | 0 yonglin_zhang/C/link_list/src/delete.c | 0 yonglin_zhang/C/link_list/src/init_and_insert.c | 0 yonglin_zhang/C/link_list/src/search.c | 0 yonglin_zhang/C/link_list/src/sort.c | 0 yonglin_zhang/C/link_list/src/update.c | 0 8 files changed, 1 insertion(+) create mode 100644 yonglin_zhang/C/CMakeLists.txt create mode 100644 yonglin_zhang/C/link_list/CMakeLists.txt create mode 100644 yonglin_zhang/C/link_list/include/link_list.h create mode 100644 yonglin_zhang/C/link_list/src/delete.c create mode 100644 yonglin_zhang/C/link_list/src/init_and_insert.c create mode 100644 yonglin_zhang/C/link_list/src/search.c create mode 100644 yonglin_zhang/C/link_list/src/sort.c create mode 100644 yonglin_zhang/C/link_list/src/update.c diff --git a/yonglin_zhang/C/CMakeLists.txt b/yonglin_zhang/C/CMakeLists.txt new file mode 100644 index 0000000..b2ce098 --- /dev/null +++ b/yonglin_zhang/C/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(link_list_with_head) \ No newline at end of file diff --git a/yonglin_zhang/C/link_list/CMakeLists.txt b/yonglin_zhang/C/link_list/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h new file mode 100644 index 0000000..e69de29 diff --git a/yonglin_zhang/C/link_list/src/delete.c b/yonglin_zhang/C/link_list/src/delete.c new file mode 100644 index 0000000..e69de29 diff --git a/yonglin_zhang/C/link_list/src/init_and_insert.c b/yonglin_zhang/C/link_list/src/init_and_insert.c new file mode 100644 index 0000000..e69de29 diff --git a/yonglin_zhang/C/link_list/src/search.c b/yonglin_zhang/C/link_list/src/search.c new file mode 100644 index 0000000..e69de29 diff --git a/yonglin_zhang/C/link_list/src/sort.c b/yonglin_zhang/C/link_list/src/sort.c new file mode 100644 index 0000000..e69de29 diff --git a/yonglin_zhang/C/link_list/src/update.c b/yonglin_zhang/C/link_list/src/update.c new file mode 100644 index 0000000..e69de29 -- Gitee From f125f4509a8eeb191f3b363683cc8ec6da5aeb4a Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 21:18:51 +0800 Subject: [PATCH 03/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/errno.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 yonglin_zhang/C/link_list/include/errno.c diff --git a/yonglin_zhang/C/link_list/include/errno.c b/yonglin_zhang/C/link_list/include/errno.c new file mode 100644 index 0000000..d10e137 --- /dev/null +++ b/yonglin_zhang/C/link_list/include/errno.c @@ -0,0 +1,23 @@ +/** + * \file errno.h + * + * \brief 错误码表 + */ + +#ifndef ERRNO_H +#define ERRNO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define ALG_OK 0x0000 /** < 操作成功 */ +#define ALG_ERR_BAD_INPUT_DATA 0x0001 /** < 输入数据不合法 */ +#define ALG_ERR_ALLOC_FAILED 0x0002 /** < 内存申请失败 */ +#define ALG_ERR_BUFFER_TOO_SMALL 0x0003 /** < buffer太小 */ + +#ifdef __cplusplus +} +#endif + +#endif /* ERRNO_H */ -- Gitee From 227b687b950bbcb663be5c7ab1a8630821744ab1 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 21:27:09 +0800 Subject: [PATCH 04/37] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=87=8D=E5=A4=8D=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E7=9A=84=E9=94=99=E8=AF=AF=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/errno.c | 1 + 1 file changed, 1 insertion(+) diff --git a/yonglin_zhang/C/link_list/include/errno.c b/yonglin_zhang/C/link_list/include/errno.c index d10e137..e92afff 100644 --- a/yonglin_zhang/C/link_list/include/errno.c +++ b/yonglin_zhang/C/link_list/include/errno.c @@ -15,6 +15,7 @@ extern "C" { #define ALG_ERR_BAD_INPUT_DATA 0x0001 /** < 输入数据不合法 */ #define ALG_ERR_ALLOC_FAILED 0x0002 /** < 内存申请失败 */ #define ALG_ERR_BUFFER_TOO_SMALL 0x0003 /** < buffer太小 */ +#define ALG_ERR_ALREADY_INIT 0x0004 /** < 重复初始化 */ #ifdef __cplusplus } -- Gitee From dbbfafd07d3a31cd50ccf2b894584cb8a51514d1 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 22:14:23 +0800 Subject: [PATCH 05/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/errno.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yonglin_zhang/C/link_list/include/errno.c b/yonglin_zhang/C/link_list/include/errno.c index e92afff..256be69 100644 --- a/yonglin_zhang/C/link_list/include/errno.c +++ b/yonglin_zhang/C/link_list/include/errno.c @@ -16,6 +16,9 @@ extern "C" { #define ALG_ERR_ALLOC_FAILED 0x0002 /** < 内存申请失败 */ #define ALG_ERR_BUFFER_TOO_SMALL 0x0003 /** < buffer太小 */ #define ALG_ERR_ALREADY_INIT 0x0004 /** < 重复初始化 */ +#define ALG_ERR_NOT_INIT 0x0005 /** < 没有初始化 */ +#define ALG_ERR_POS_NOT_IN_RANGE 0x0006 /** < 链表中没有该位置 */ +#define ALG_ERR_EMPTY_LIST 0x0007 /** < 链表为空 */ #ifdef __cplusplus } -- Gitee From 2f45ce9d33fbef5de248096ff9bc93b3a5928ee1 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 22:14:43 +0800 Subject: [PATCH 06/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index e69de29..65ac42a 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -0,0 +1,241 @@ +/** + * \file link_list.h + * + * \brief 链表接口头文件 + */ + +#ifndef LINK_LIST_H +#define LINK_LIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define DATA_TYPE int + +/** + * \brief 链表结构体。 + */ +typedef struct _node node; + +/** 初始化操作 */ + +/** + * \brief 链表的初始化。 + * + * \note 此接口应当在链表使用前调用,且仅调用一次,并且传入的参数应当指向NULL,否则默认为有数据的节点,不进行初始化。 + * + * \param head[in/out] 链表的头节点的地址。 + * + * \return #ALG_OK 操作成功。 + * \return #ALG_ERR_BAD_INPUT_DATA 输入数据非法。 + * \return #ALG_ERR_ALLOC_FAILED 内存申请失败。 + * \return #ALG_ERR_ALREADY_INIT 重复初始化。 + */ +int init(node **head); + +/** 插入相关操作 */ + +/** + * \brief 添加一个节点(默认为头插法)。 + * + * \note 为了避免浅拷贝的情况出现,此处采用深拷贝模式。 + * + * \param head[in/out] 链表的头节点。 + * \param target[in] 待添加节点。 + * + * \return #ALG_OK 操作成功。 + */ +int add(node **head, node data); + +/** + * \brief 头插法添加一个节点。 + * + * + * \param head[in/out] 链表的头节点。 + * \param target[in] 待添加节点。 + * + * \return #ALG_OK 操作成功。 + */ +int add_head(node **head, node data); + +/** + * \brief 尾插法添加一个节点。 + * + * + * \param head[in/out] 链表的头节点。 + * \param target[in] 待添加节点。 + * + * \return #ALG_OK 操作成功。 + */ +int add_end(node **head, node data); + +/** + * \brief 在位置X处添加一个节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int add_pos_x(); + +/** 删除操作 */ + +/** + * \brief 删除数据为X的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int delete_data_x(); + +/** + * \brief 删除位置为X的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int delete_pos_x(); + +/** + * \brief 清空从位置X之后的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int delete_after_pos_x(); + +/** + * \brief 清空从位置X之前的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int delete_before_pos_x(); + +/** + * \brief 清空整个链表。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int clear(); + + +/** 排序操作 */ + +/** + * \brief 反转链表。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int erverse(); + +/** + * \brief 升序排序。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int ascend(); + +/** + * \brief 降序排序。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int descend(); + + +/** 查询操作 */ + + +/** + * \brief 打印整个链表。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int show_all(); + +/** + * \brief 查询数值为X的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int search_data_x(); + +/** + * \brief 查询位置为X的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int search_pos_x(); + +/** + * \brief 返回整个链表的长度。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int get_length(); + + +/** 更新操作 */ + + +/** + * \brief 更新数据为X的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int update_data_x(); + +/** + * \brief 更新位置为X的节点。 + * + * + * \param + * + * \return #ALG_OK 操作成功。 + */ +int update_pos_x(); + + +#ifdef __cplusplus +} +#endif + +#endif /* LINK_LIST_H */ \ No newline at end of file -- Gitee From 0354c88b59b13c380c050e55f4da1cb11a571e5d Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 22:34:25 +0800 Subject: [PATCH 07/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0cmake=EF=BC=8C=E7=8E=B0?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E5=B7=B2=E7=BB=8F=E5=8F=AF=E4=BB=A5=E7=BC=96?= =?UTF-8?q?=E5=87=BA=E6=9D=A5=E5=8A=A8=E6=80=81=E5=BA=93=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/CMakeLists.txt | 2 +- yonglin_zhang/C/link_list/CMakeLists.txt | 1 + yonglin_zhang/C/link_list/src/CMakeLists.txt | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 yonglin_zhang/C/link_list/src/CMakeLists.txt diff --git a/yonglin_zhang/C/CMakeLists.txt b/yonglin_zhang/C/CMakeLists.txt index b2ce098..cdc1dde 100644 --- a/yonglin_zhang/C/CMakeLists.txt +++ b/yonglin_zhang/C/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(link_list_with_head) \ No newline at end of file +add_subdirectory(link_list) \ No newline at end of file diff --git a/yonglin_zhang/C/link_list/CMakeLists.txt b/yonglin_zhang/C/link_list/CMakeLists.txt index e69de29..130b119 100644 --- a/yonglin_zhang/C/link_list/CMakeLists.txt +++ b/yonglin_zhang/C/link_list/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(src) \ No newline at end of file diff --git a/yonglin_zhang/C/link_list/src/CMakeLists.txt b/yonglin_zhang/C/link_list/src/CMakeLists.txt new file mode 100644 index 0000000..d2a2fd2 --- /dev/null +++ b/yonglin_zhang/C/link_list/src/CMakeLists.txt @@ -0,0 +1,15 @@ +set(LIB_SOURCES + delete.c + init_and_insert.c + search.c + sort.c + update.c +) + +set(INCLUDE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}/../include" +) + +include_directories(${INCLUDE_DIRS}) + +add_library(link_list SHARED ${LIB_SOURCES}) -- Gitee From a51e905b7a9626a412b4b9701acde25cd7719e4c Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 22:44:34 +0800 Subject: [PATCH 08/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index 65ac42a..e3683ea 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -16,7 +16,10 @@ extern "C" { /** * \brief 链表结构体。 */ -typedef struct _node node; +typedef struct _node{ + DATA_TYPE data; + struct _node *next; +}node; /** 初始化操作 */ -- Gitee From b3b5cbf63eada2fd536ff9f559e9973ca227615e Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 22:46:46 +0800 Subject: [PATCH 09/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/{errno.c => errno.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename yonglin_zhang/C/link_list/include/{errno.c => errno.h} (100%) diff --git a/yonglin_zhang/C/link_list/include/errno.c b/yonglin_zhang/C/link_list/include/errno.h similarity index 100% rename from yonglin_zhang/C/link_list/include/errno.c rename to yonglin_zhang/C/link_list/include/errno.h -- Gitee From b3c0dcb6c7c6db762789384d7b7f7c2641fbed49 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 23:09:42 +0800 Subject: [PATCH 10/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9ignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1b5addf..5711453 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.layout *.depend *.exe -build \ No newline at end of file +build +.vscode \ No newline at end of file -- Gitee From 184f8be03cc06b5c17f35a5019fbc4f2c6e090c7 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 23:10:11 +0800 Subject: [PATCH 11/37] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=87=8D=E5=90=8D=E5=B9=B6=E5=AE=9A=E4=B9=89=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../C/link_list/include/{errno.h => alg_errno.h} | 8 ++++---- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename yonglin_zhang/C/link_list/include/{errno.h => alg_errno.h} (89%) diff --git a/yonglin_zhang/C/link_list/include/errno.h b/yonglin_zhang/C/link_list/include/alg_errno.h similarity index 89% rename from yonglin_zhang/C/link_list/include/errno.h rename to yonglin_zhang/C/link_list/include/alg_errno.h index 256be69..57b556d 100644 --- a/yonglin_zhang/C/link_list/include/errno.h +++ b/yonglin_zhang/C/link_list/include/alg_errno.h @@ -1,11 +1,11 @@ /** - * \file errno.h + * \file alg_errno.h * * \brief 错误码表 */ -#ifndef ERRNO_H -#define ERRNO_H +#ifndef ALG_ERRNO_H +#define ALG_ERRNO_H #ifdef __cplusplus extern "C" { @@ -24,4 +24,4 @@ extern "C" { } #endif -#endif /* ERRNO_H */ +#endif /* ALG_ERRNO_H */ diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index e3683ea..eee1c32 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -49,7 +49,7 @@ int init(node **head); * * \return #ALG_OK 操作成功。 */ -int add(node **head, node data); +int add(node *head, node data); /** * \brief 头插法添加一个节点。 -- Gitee From cccb81973977a0f6eb1ae143be37e853f94c793f Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Wed, 14 Jul 2021 23:10:32 +0800 Subject: [PATCH 12/37] =?UTF-8?q?=E5=AE=9E=E7=8E=B0init=E5=92=8Cadd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../C/link_list/src/init_and_insert.c | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/init_and_insert.c b/yonglin_zhang/C/link_list/src/init_and_insert.c index e69de29..6ebcd3a 100644 --- a/yonglin_zhang/C/link_list/src/init_and_insert.c +++ b/yonglin_zhang/C/link_list/src/init_and_insert.c @@ -0,0 +1,40 @@ +#include +#include +#include "link_list.h" +#include "alg_errno.h" + +int init(node **head) +{ + //传入空指针 + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + //传入的指针指向不为空则视为已经初始化过 + if((*head) != NULL) { + return ALG_ERR_ALREADY_INIT; + } + + //申请内存并初始化 + (*head) = (node*)malloc(sizeof(node)); + (*head)->next = NULL; + (*head)->data = -1; + + return ALG_OK; +} + +int add(node *head, node data) +{ + node *t = (node*)malloc(sizeof(node)); + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + t->next = head->next; + t->data = data.data; + + head->next = t; + + return ALG_OK; +} \ No newline at end of file -- Gitee From f2de5984120dbf0b2bd1f539fb8451520e7e1fce Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 10:13:42 +0800 Subject: [PATCH 13/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/CMakeLists.txt | 1 + yonglin_zhang/C/dep/CMakeLists.txt | 0 yonglin_zhang/C/{link_list/include => dep}/alg_errno.h | 0 yonglin_zhang/C/link_list/src/CMakeLists.txt | 1 + 4 files changed, 2 insertions(+) create mode 100644 yonglin_zhang/C/dep/CMakeLists.txt rename yonglin_zhang/C/{link_list/include => dep}/alg_errno.h (100%) diff --git a/yonglin_zhang/C/CMakeLists.txt b/yonglin_zhang/C/CMakeLists.txt index cdc1dde..61b9e3c 100644 --- a/yonglin_zhang/C/CMakeLists.txt +++ b/yonglin_zhang/C/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(dep) add_subdirectory(link_list) \ No newline at end of file diff --git a/yonglin_zhang/C/dep/CMakeLists.txt b/yonglin_zhang/C/dep/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/yonglin_zhang/C/link_list/include/alg_errno.h b/yonglin_zhang/C/dep/alg_errno.h similarity index 100% rename from yonglin_zhang/C/link_list/include/alg_errno.h rename to yonglin_zhang/C/dep/alg_errno.h diff --git a/yonglin_zhang/C/link_list/src/CMakeLists.txt b/yonglin_zhang/C/link_list/src/CMakeLists.txt index d2a2fd2..018b8dc 100644 --- a/yonglin_zhang/C/link_list/src/CMakeLists.txt +++ b/yonglin_zhang/C/link_list/src/CMakeLists.txt @@ -8,6 +8,7 @@ set(LIB_SOURCES set(INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../include" + "${CMAKE_CURRENT_SOURCE_DIR}/../../dep" ) include_directories(${INCLUDE_DIRS}) -- Gitee From d74d32bfcbe43e5899f1c7a33de7d399758735ff Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 10:50:18 +0800 Subject: [PATCH 14/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index eee1c32..cd7586b 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -60,7 +60,7 @@ int add(node *head, node data); * * \return #ALG_OK 操作成功。 */ -int add_head(node **head, node data); +int add_head(node *head, node data); /** * \brief 尾插法添加一个节点。 @@ -71,7 +71,7 @@ int add_head(node **head, node data); * * \return #ALG_OK 操作成功。 */ -int add_end(node **head, node data); +int add_end(node *head, node data); /** * \brief 在位置X处添加一个节点。 -- Gitee From f231a9efc900c5a963a3194221d1ba4f248797d3 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 10:50:46 +0800 Subject: [PATCH 15/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=B4=E6=8F=92?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/init_and_insert.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/init_and_insert.c b/yonglin_zhang/C/link_list/src/init_and_insert.c index 6ebcd3a..ff11b18 100644 --- a/yonglin_zhang/C/link_list/src/init_and_insert.c +++ b/yonglin_zhang/C/link_list/src/init_and_insert.c @@ -23,6 +23,7 @@ int init(node **head) return ALG_OK; } +/* 采用深拷贝的方式进行,避免内存问题 */ int add(node *head, node data) { node *t = (node*)malloc(sizeof(node)); @@ -37,4 +38,10 @@ int add(node *head, node data) head->next = t; return ALG_OK; +} + +/* 头插法与add函数相同 */ +int add_head(node *head, node data) +{ + return add(head, data); } \ No newline at end of file -- Gitee From 8cf494ee54ccb7fb0856637bd19883e604d908c5 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 10:51:01 +0800 Subject: [PATCH 16/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9cmake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yonglin_zhang/C/link_list/CMakeLists.txt b/yonglin_zhang/C/link_list/CMakeLists.txt index 130b119..3b583cc 100644 --- a/yonglin_zhang/C/link_list/CMakeLists.txt +++ b/yonglin_zhang/C/link_list/CMakeLists.txt @@ -1 +1,5 @@ +cmake_minimum_required(VERSION 3.0) + +project(link_likt C) + add_subdirectory(src) \ No newline at end of file -- Gitee From 914b1f7a09667b1fc3c3666d8e03e5894df26162 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 10:56:47 +0800 Subject: [PATCH 17/37] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=B0=BE=E6=8F=92?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../C/link_list/src/init_and_insert.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/init_and_insert.c b/yonglin_zhang/C/link_list/src/init_and_insert.c index ff11b18..fecca9e 100644 --- a/yonglin_zhang/C/link_list/src/init_and_insert.c +++ b/yonglin_zhang/C/link_list/src/init_and_insert.c @@ -44,4 +44,23 @@ int add(node *head, node data) int add_head(node *head, node data) { return add(head, data); +} + +int add_end(node *head, node data) +{ + node *t = NULL; + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + t = head; + while(t->next != NULL) { + t = t->next; + } + + node *temp = (node *)malloc(sizeof(node)); + temp->data = data.data; + temp->next = NULL; + head->next = temp; + return ALG_OK; } \ No newline at end of file -- Gitee From 9ce6f3eaa8e4cc50ef7e83ff8d95824964693f94 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 11:07:25 +0800 Subject: [PATCH 18/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index cd7586b..433837b 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -81,7 +81,7 @@ int add_end(node *head, node data); * * \return #ALG_OK 操作成功。 */ -int add_pos_x(); +int add_pos_x(node *head, node data); /** 删除操作 */ -- Gitee From ff3b55129364839ff161f991a5321a1c7eb830b5 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 11:29:54 +0800 Subject: [PATCH 19/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index 433837b..0b6a70f 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -45,7 +45,7 @@ int init(node **head); * \note 为了避免浅拷贝的情况出现,此处采用深拷贝模式。 * * \param head[in/out] 链表的头节点。 - * \param target[in] 待添加节点。 + * \param data[in] 待添加节点。 * * \return #ALG_OK 操作成功。 */ @@ -56,7 +56,7 @@ int add(node *head, node data); * * * \param head[in/out] 链表的头节点。 - * \param target[in] 待添加节点。 + * \param data[in] 待添加节点。 * * \return #ALG_OK 操作成功。 */ @@ -67,7 +67,7 @@ int add_head(node *head, node data); * * * \param head[in/out] 链表的头节点。 - * \param target[in] 待添加节点。 + * \param data[in] 待添加节点。 * * \return #ALG_OK 操作成功。 */ @@ -77,7 +77,7 @@ int add_end(node *head, node data); * \brief 在位置X处添加一个节点。 * * - * \param + * \param head[in/out] 链表的头节点 * * \return #ALG_OK 操作成功。 */ -- Gitee From 72b40ae61fd0377e59eaf1ea0743a3f2a6487cc1 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 11:31:38 +0800 Subject: [PATCH 20/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index 0b6a70f..ccbdf2c 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -81,7 +81,7 @@ int add_end(node *head, node data); * * \return #ALG_OK 操作成功。 */ -int add_pos_x(node *head, node data); +int add_pos_x(node *head, node data, int pos); /** 删除操作 */ -- Gitee From 8d1e952a0adb0f053442bf571631b7af440a9973 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 13:30:33 +0800 Subject: [PATCH 21/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 1 + 1 file changed, 1 insertion(+) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index ccbdf2c..3869985 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -76,6 +76,7 @@ int add_end(node *head, node data); /** * \brief 在位置X处添加一个节点。 * + * \note 头节点默认位置为0 * * \param head[in/out] 链表的头节点 * -- Gitee From d69270f94c81e2d4dc262b4f749b2398e7669202 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 13:30:57 +0800 Subject: [PATCH 22/37] =?UTF-8?q?=E6=8C=89=E4=BD=8D=E7=BD=AE=E6=8F=92?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../C/link_list/src/init_and_insert.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/init_and_insert.c b/yonglin_zhang/C/link_list/src/init_and_insert.c index fecca9e..f2ac0fb 100644 --- a/yonglin_zhang/C/link_list/src/init_and_insert.c +++ b/yonglin_zhang/C/link_list/src/init_and_insert.c @@ -63,4 +63,37 @@ int add_end(node *head, node data) temp->next = NULL; head->next = temp; return ALG_OK; +} + +/* 在链表X处插入数据 */ +int add_pos_x(node *head, node data, int pos) +{ + node *p; + int counter = 0; + + if(head == NULL || pos == 0) { //头节点位置为0 + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head; + while(p->next != NULL) { + counter++; + if(counter == pos) { + node *t = (node *)malloc(sizeof(node)); + t->next = p->next; + t->data = data.data; + p->next = t; + return ALG_OK; + } + } + + if(p->next == NULL && (counter + 1) == pos) { + node *t = (node *)malloc(sizeof(node)); + t->next = p->next; + t->data = data.data; + p->next = t; + return ALG_OK; + } + + return ALG_ERR_POS_NOT_IN_RANGE; } \ No newline at end of file -- Gitee From 4be254fe7b64dccf4fc83d1da6faf94af7c7ca56 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 16:29:38 +0800 Subject: [PATCH 23/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index 3869985..58a8b0b 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -94,7 +94,7 @@ int add_pos_x(node *head, node data, int pos); * * \return #ALG_OK 操作成功。 */ -int delete_data_x(); +int delete_data_x(node *head, node data); /** * \brief 删除位置为X的节点。 -- Gitee From ad881640c0a948a7aa2ce37b92ab9104fdfc6cff Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 16:50:06 +0800 Subject: [PATCH 24/37] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=AD=BB=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/init_and_insert.c | 1 + 1 file changed, 1 insertion(+) diff --git a/yonglin_zhang/C/link_list/src/init_and_insert.c b/yonglin_zhang/C/link_list/src/init_and_insert.c index f2ac0fb..b7dfc1b 100644 --- a/yonglin_zhang/C/link_list/src/init_and_insert.c +++ b/yonglin_zhang/C/link_list/src/init_and_insert.c @@ -85,6 +85,7 @@ int add_pos_x(node *head, node data, int pos) p->next = t; return ALG_OK; } + p = p->next; } if(p->next == NULL && (counter + 1) == pos) { -- Gitee From 2fbab198c7208b2aa6758435a0232154078f58b0 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 16:51:37 +0800 Subject: [PATCH 25/37] =?UTF-8?q?=E2=80=9C=E5=AE=9E=E7=8E=B0=E6=8C=89?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=88=A0=E9=99=A4=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/delete.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/delete.c b/yonglin_zhang/C/link_list/src/delete.c index e69de29..4781a50 100644 --- a/yonglin_zhang/C/link_list/src/delete.c +++ b/yonglin_zhang/C/link_list/src/delete.c @@ -0,0 +1,24 @@ +#include +#include +#include "link_list.h" +#include "alg_errno.h" + +int delete_data_x(node *head, node data) +{ + node *p = NULL; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head; + + while(p->next != NULL) { + if(p->next->data == data.data) { + node *t = p->next; + p->next = t->next; + continue; + } + p = p->next; + } +} \ No newline at end of file -- Gitee From 584202ef96b8243f96ccb8663bb37bd1575e5e38 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 16:53:48 +0800 Subject: [PATCH 26/37] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=90=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/dep/alg_errno.h | 1 + 1 file changed, 1 insertion(+) diff --git a/yonglin_zhang/C/dep/alg_errno.h b/yonglin_zhang/C/dep/alg_errno.h index 57b556d..2d51eba 100644 --- a/yonglin_zhang/C/dep/alg_errno.h +++ b/yonglin_zhang/C/dep/alg_errno.h @@ -19,6 +19,7 @@ extern "C" { #define ALG_ERR_NOT_INIT 0x0005 /** < 没有初始化 */ #define ALG_ERR_POS_NOT_IN_RANGE 0x0006 /** < 链表中没有该位置 */ #define ALG_ERR_EMPTY_LIST 0x0007 /** < 链表为空 */ +#define ALG_ERR_NO_THIS_POINT 0x0008 /** < 没有包含该数据的节点 */ #ifdef __cplusplus } -- Gitee From d276980276d54b251582347e7c3b183fa945ae45 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 16:54:48 +0800 Subject: [PATCH 27/37] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8C=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=9B=E8=A1=8C=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/delete.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/src/delete.c b/yonglin_zhang/C/link_list/src/delete.c index 4781a50..32026ea 100644 --- a/yonglin_zhang/C/link_list/src/delete.c +++ b/yonglin_zhang/C/link_list/src/delete.c @@ -17,8 +17,10 @@ int delete_data_x(node *head, node data) if(p->next->data == data.data) { node *t = p->next; p->next = t->next; - continue; + return ALG_OK; } p = p->next; } + + return ALG_ERR_NO_THIS_POINT; } \ No newline at end of file -- Gitee From 181a824ac98eccd44c92ac8fd7ee830d418b8a97 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 17:17:57 +0800 Subject: [PATCH 28/37] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=88=A0=E9=99=A4=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/delete.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/delete.c b/yonglin_zhang/C/link_list/src/delete.c index 32026ea..70fc87f 100644 --- a/yonglin_zhang/C/link_list/src/delete.c +++ b/yonglin_zhang/C/link_list/src/delete.c @@ -23,4 +23,28 @@ int delete_data_x(node *head, node data) } return ALG_ERR_NO_THIS_POINT; +} + +int delete_pos_x(node *head, int pos) +{ + int counter = 0; + node *p = NULL; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head; + while(p->next != NULL) { + counter++; + if(counter == pos) { + node *t = p->next; + p->next = t->next; + free(t); + return ALG_OK; + } + p = p->next; + } + + return ALG_ERR_POS_NOT_IN_RANGE; } \ No newline at end of file -- Gitee From c380f74f03243ef7836b4c509f8ad3208c5a0e57 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 17:18:50 +0800 Subject: [PATCH 29/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index 58a8b0b..a24dd34 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -104,7 +104,7 @@ int delete_data_x(node *head, node data); * * \return #ALG_OK 操作成功。 */ -int delete_pos_x(); +int delete_pos_x(node *head, int pos); /** * \brief 清空从位置X之后的节点。 -- Gitee From 062f3d35bdda804912465f137359ee7bfdf19ab3 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 20:48:49 +0800 Subject: [PATCH 30/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index a24dd34..73ce45a 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -114,7 +114,7 @@ int delete_pos_x(node *head, int pos); * * \return #ALG_OK 操作成功。 */ -int delete_after_pos_x(); +int delete_after_pos_x(node *head, int pos); /** * \brief 清空从位置X之前的节点。 -- Gitee From dc113c15f60b8bad681eda6d22cea39cb60e566e Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 20:49:23 +0800 Subject: [PATCH 31/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/delete.c | 31 +++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/src/delete.c b/yonglin_zhang/C/link_list/src/delete.c index 70fc87f..23916fc 100644 --- a/yonglin_zhang/C/link_list/src/delete.c +++ b/yonglin_zhang/C/link_list/src/delete.c @@ -47,4 +47,33 @@ int delete_pos_x(node *head, int pos) } return ALG_ERR_POS_NOT_IN_RANGE; -} \ No newline at end of file +} + +int delete_after_pos_x(node *head, int pos) +{ + node *p; + int counter = 0; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head; + while(p != NULL) { + counter++; + if(counter == pos) { + node *t = p->next; + while(t != NULL) { + node *temp = t; + t = t->next; + free(t); + } + p->next = NULL; + return ALG_OK; + } + p = p->next; + } + + return ALG_ERR_POS_NOT_IN_RANGE; +} + -- Gitee From 81a152ce34269a5fd557ed3b4cb0987e1965e7a3 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 20:50:33 +0800 Subject: [PATCH 32/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index 73ce45a..136b914 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -124,7 +124,7 @@ int delete_after_pos_x(node *head, int pos); * * \return #ALG_OK 操作成功。 */ -int delete_before_pos_x(); +int delete_before_pos_x(node *head, int pos); /** * \brief 清空整个链表。 -- Gitee From e2106fcad80e2aef34e12627c0acf7da2358ee3c Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 21:04:06 +0800 Subject: [PATCH 33/37] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=9F=90=E4=B8=AA=E4=BD=8D=E7=BD=AE=E4=B9=8B=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/delete.c | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/src/delete.c b/yonglin_zhang/C/link_list/src/delete.c index 23916fc..2b26585 100644 --- a/yonglin_zhang/C/link_list/src/delete.c +++ b/yonglin_zhang/C/link_list/src/delete.c @@ -51,7 +51,7 @@ int delete_pos_x(node *head, int pos) int delete_after_pos_x(node *head, int pos) { - node *p; + node *p = NULL; int counter = 0; if(head == NULL) { @@ -77,3 +77,42 @@ int delete_after_pos_x(node *head, int pos) return ALG_ERR_POS_NOT_IN_RANGE; } +int delete_before_pos_x(node *head, int pos) +{ + node *p = NULL; + int counter = 0; + int flag = 0; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head; + while(p != NULL) { + counter++; + if(counter == pos) { + flag = 1; + break; + } + } + + if(flag) { + p = head; + counter = 0; + while(head->next != NULL) { + counter++; + if(counter == pos) { + break; + } + else { + p = head->next; + head = head->next; + free(p); + } + } + return ALG_OK; + } + else { + return ALG_ERR_POS_NOT_IN_RANGE; + } +} \ No newline at end of file -- Gitee From a0b8d869a3464297100ad4f1f673d84d54e73192 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 21:07:14 +0800 Subject: [PATCH 34/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index 136b914..e4693c8 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -134,7 +134,7 @@ int delete_before_pos_x(node *head, int pos); * * \return #ALG_OK 操作成功。 */ -int clear(); +int clear(node *head); /** 排序操作 */ -- Gitee From 855e3c7f7894de5d49b3f224889e7ae1eeb21108 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 21:07:52 +0800 Subject: [PATCH 35/37] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E9=93=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/delete.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/delete.c b/yonglin_zhang/C/link_list/src/delete.c index 2b26585..bd96595 100644 --- a/yonglin_zhang/C/link_list/src/delete.c +++ b/yonglin_zhang/C/link_list/src/delete.c @@ -115,4 +115,24 @@ int delete_before_pos_x(node *head, int pos) else { return ALG_ERR_POS_NOT_IN_RANGE; } +} + +int clear(node *head) +{ + node *p; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head->next; + head->next = NULL; + + while(p != NULL) { + node *t = p; + p = p->next; + free(t); + } + + return ALG_OK; } \ No newline at end of file -- Gitee From 95b466cb2af5181e012b81da42cff5bcf2f1543f Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 21:10:00 +0800 Subject: [PATCH 36/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/include/link_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yonglin_zhang/C/link_list/include/link_list.h b/yonglin_zhang/C/link_list/include/link_list.h index e4693c8..9f3c85f 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -147,7 +147,7 @@ int clear(node *head); * * \return #ALG_OK 操作成功。 */ -int erverse(); +int reverse(node *head); /** * \brief 升序排序。 -- Gitee From 32db48450ad126cd96a99964c2c1f8f7c53a85bc Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Thu, 15 Jul 2021 21:22:09 +0800 Subject: [PATCH 37/37] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yonglin_zhang/C/link_list/src/sort.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/sort.c b/yonglin_zhang/C/link_list/src/sort.c index e69de29..42c3f77 100644 --- a/yonglin_zhang/C/link_list/src/sort.c +++ b/yonglin_zhang/C/link_list/src/sort.c @@ -0,0 +1,5 @@ +#include +#include +#include "link_list.h" +#include "alg_errno.h" + -- Gitee