From 383480b502d17a331cbd72b3d3db4e04fb4645e0 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Sat, 17 Jul 2021 21:46:38 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8F=8D=E8=BD=AC?= =?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/sort.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/sort.c b/yonglin_zhang/C/link_list/src/sort.c index 42c3f77..ca208a4 100644 --- a/yonglin_zhang/C/link_list/src/sort.c +++ b/yonglin_zhang/C/link_list/src/sort.c @@ -3,3 +3,25 @@ #include "link_list.h" #include "alg_errno.h" +int reverse(node *head) +{ + node *p = NULL; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + //空链表不需要反转 + if(head->next == NULL) { + return ALG_OK; + } + + p = head->next; + head->next = NULL; + while(p != NULL) { + node *t = p; + p = p->next; + t->next = head->next; + head->next = t; + } + return ALG_OK; +} \ No newline at end of file -- Gitee From 2d68d63821473ce9a5a27b0f8bb6496fcc0ca73a Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Tue, 3 Aug 2021 21:26:43 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8D=87=E5=BA=8F?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= 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 +- yonglin_zhang/C/link_list/src/sort.c | 31 ++++++++++++++++++- 2 files changed, 31 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 9f3c85f..70ebf77 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -157,7 +157,7 @@ int reverse(node *head); * * \return #ALG_OK 操作成功。 */ -int ascend(); +int ascend(node *head); /** * \brief 降序排序。 diff --git a/yonglin_zhang/C/link_list/src/sort.c b/yonglin_zhang/C/link_list/src/sort.c index ca208a4..42d90e6 100644 --- a/yonglin_zhang/C/link_list/src/sort.c +++ b/yonglin_zhang/C/link_list/src/sort.c @@ -24,4 +24,33 @@ int reverse(node *head) head->next = t; } return ALG_OK; -} \ No newline at end of file +} + +int ascend(node *head) +{ + node *p = NULL; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head->next; + + if(p == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + while(p != NULL) { + node *t = p->next; + while(t != NULL) { + if(t->data < p->data) { + DATA_TYPE temp = t->data; + t->data = p->data; + p->data = temp; + } + } + } + + return ALG_OK; +} + -- Gitee From a1c82a725745ec035fb1809a41d2bffabf0b1707 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Tue, 3 Aug 2021 21:28:41 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E5=8D=87=E5=BA=8F=E6=8E=92=E5=BA=8F?= =?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/include/link_list.h | 2 +- yonglin_zhang/C/link_list/src/sort.c | 30 +++++++++++++++++++ 2 files changed, 31 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 70ebf77..719c4c4 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -167,7 +167,7 @@ int ascend(node *head); * * \return #ALG_OK 操作成功。 */ -int descend(); +int descend(node *head); /** 查询操作 */ diff --git a/yonglin_zhang/C/link_list/src/sort.c b/yonglin_zhang/C/link_list/src/sort.c index 42d90e6..346f140 100644 --- a/yonglin_zhang/C/link_list/src/sort.c +++ b/yonglin_zhang/C/link_list/src/sort.c @@ -54,3 +54,33 @@ int ascend(node *head) return ALG_OK; } +int descend(node *head) +{ + node *p = NULL; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + if(head->next == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + + p = head->next; + + while(p != NULL) { + node *t = p->next; + while(t != NULL) { + if(t->data > p->data) { + DATA_TYPE temp = t->data; + t->data = p->data; + p->data = temp; + } + } + } + + return ALG_OK; +} \ No newline at end of file -- Gitee From 4cdbc87ac28bf33f5ff817c181ace6f5af3d7504 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Tue, 3 Aug 2021 22:05:48 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E8=8A=82=E7=82=B9=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/include/link_list.h | 2 +- yonglin_zhang/C/link_list/src/search.c | 22 +++++++++++++++++++ 2 files changed, 23 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 719c4c4..be41832 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -181,7 +181,7 @@ int descend(node *head); * * \return #ALG_OK 操作成功。 */ -int show_all(); +int show_all(node *head); /** * \brief 查询数值为X的节点。 diff --git a/yonglin_zhang/C/link_list/src/search.c b/yonglin_zhang/C/link_list/src/search.c index e69de29..786f6a1 100644 --- a/yonglin_zhang/C/link_list/src/search.c +++ b/yonglin_zhang/C/link_list/src/search.c @@ -0,0 +1,22 @@ +#include +#include +#include "link_list.h" +#include "alg_errno.h" + +int show_all(node *head) +{ + node *t = head; + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + if(head->next == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + printf("link list:\n"); + while(t != NULL) { + printf("%d, ", t->data); + t = t->next; + } + return ALG_OK; +} \ No newline at end of file -- Gitee From f448285360c880187cc7fe60fed2c05a138be455 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Tue, 3 Aug 2021 22:08:08 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=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/sort.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yonglin_zhang/C/link_list/src/sort.c b/yonglin_zhang/C/link_list/src/sort.c index 346f140..fd6242c 100644 --- a/yonglin_zhang/C/link_list/src/sort.c +++ b/yonglin_zhang/C/link_list/src/sort.c @@ -48,7 +48,9 @@ int ascend(node *head) t->data = p->data; p->data = temp; } + t = t->next; } + p = p->next; } return ALG_OK; @@ -79,7 +81,9 @@ int descend(node *head) t->data = p->data; p->data = temp; } + t = t->next; } + p = p->next; } return ALG_OK; -- Gitee From 34bac2b35518a409bd8e76d2e0d3f016cce3dc21 Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Tue, 3 Aug 2021 22:14:29 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=89=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E6=9F=A5=E8=AF=A2=E8=8A=82=E7=82=B9=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= 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 +- yonglin_zhang/C/link_list/src/search.c | 23 +++++++++++++++++++ 2 files changed, 24 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 be41832..8131fd5 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -191,7 +191,7 @@ int show_all(node *head); * * \return #ALG_OK 操作成功。 */ -int search_data_x(); +int search_data_x(node *head, DATA_TYPE target_data); /** * \brief 查询位置为X的节点。 diff --git a/yonglin_zhang/C/link_list/src/search.c b/yonglin_zhang/C/link_list/src/search.c index 786f6a1..1a78941 100644 --- a/yonglin_zhang/C/link_list/src/search.c +++ b/yonglin_zhang/C/link_list/src/search.c @@ -19,4 +19,27 @@ int show_all(node *head) t = t->next; } return ALG_OK; +} + +int search_data_x(node *head, DATA_TYPE target_data) +{ + node *t = NULL; + + if(head == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + if(head->next == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + t = head; + + while(t != NULL) { + if(t->data == target_data) { + return ALG_OK; + } + t = t->next; + } + + return ALG_ERR_NO_THIS_POINT; } \ No newline at end of file -- Gitee From 124486b4b5891e979af2f6330b47171cd5744d6d Mon Sep 17 00:00:00 2001 From: yonglin_zhang <1248825327@qq.com> Date: Tue, 3 Aug 2021 22:23:12 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E8=BF=9B=E8=A1=8C=E6=9F=A5=E6=89=BE?= 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 +- yonglin_zhang/C/link_list/src/search.c | 24 +++++++++++++++++++ 2 files changed, 25 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 8131fd5..33683f1 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -201,7 +201,7 @@ int search_data_x(node *head, DATA_TYPE target_data); * * \return #ALG_OK 操作成功。 */ -int search_pos_x(); +int search_pos_x(node *head, int pos); /** * \brief 返回整个链表的长度。 diff --git a/yonglin_zhang/C/link_list/src/search.c b/yonglin_zhang/C/link_list/src/search.c index 1a78941..d1ba905 100644 --- a/yonglin_zhang/C/link_list/src/search.c +++ b/yonglin_zhang/C/link_list/src/search.c @@ -42,4 +42,28 @@ int search_data_x(node *head, DATA_TYPE target_data) } return ALG_ERR_NO_THIS_POINT; +} + +int search_pos_x(node *head, int pos) +{ + node *t = NULL; + int counter = 0; + + if(head == NULL || pos <= 0) { + return ALG_ERR_BAD_INPUT_DATA; + } + if(head->next == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + t = head; + while(t != NULL) { + counter++; + if(counter == pos) { + return ALG_OK; + } + t = t->next; + } + + return ALG_ERR_POS_NOT_IN_RANGE; } \ No newline at end of file -- Gitee From 18e75b33ecdf824f4bd145118af08ed4960701a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=97=E7=86=8A?= <1248825327@qq.com> Date: Wed, 4 Aug 2021 09:53:06 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=8E=B7=E5=BE=97?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E7=9A=84=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 | 2 +- yonglin_zhang/C/link_list/src/search.c | 21 +++++++++++++++++++ 2 files changed, 22 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 33683f1..df472e5 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -211,7 +211,7 @@ int search_pos_x(node *head, int pos); * * \return #ALG_OK 操作成功。 */ -int get_length(); +int get_length(node *head, int *length); /** 更新操作 */ diff --git a/yonglin_zhang/C/link_list/src/search.c b/yonglin_zhang/C/link_list/src/search.c index d1ba905..b80dd28 100644 --- a/yonglin_zhang/C/link_list/src/search.c +++ b/yonglin_zhang/C/link_list/src/search.c @@ -66,4 +66,25 @@ int search_pos_x(node *head, int pos) } return ALG_ERR_POS_NOT_IN_RANGE; +} + +int get_length(node *head, int *length) +{ + node *t = NULL; + + if(head == NULL || length == NULL) { + return ALG_ERR_BAD_INPUT_DATA; + } + if(head->next == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + t = head; + + while(t != NULL) { + (*length)++; + t = t->next; + } + + return ALG_OK; } \ No newline at end of file -- Gitee From 9f453d6188baf89d22b45ec723dd8fa8cbf2dd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=97=E7=86=8A?= <1248825327@qq.com> Date: Wed, 4 Aug 2021 10:06:41 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=8C=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE?= 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 +- yonglin_zhang/C/link_list/src/update.c | 27 +++++++++++++++++++ 2 files changed, 28 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 df472e5..dce0207 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -225,7 +225,7 @@ int get_length(node *head, int *length); * * \return #ALG_OK 操作成功。 */ -int update_data_x(); +int update_data_x(node *head, DATA_TYPE target_data, DATA_TYPE new_data); /** * \brief 更新位置为X的节点。 diff --git a/yonglin_zhang/C/link_list/src/update.c b/yonglin_zhang/C/link_list/src/update.c index e69de29..c0dbfd3 100644 --- a/yonglin_zhang/C/link_list/src/update.c +++ b/yonglin_zhang/C/link_list/src/update.c @@ -0,0 +1,27 @@ +#include +#include +#include "link_list.h" +#include "alg_errno.h" + +int update_data_x(node *head, DATA_TYPE target_data, DATA_TYPE new_data) +{ + node *t = NULL; + + if(head == NULL ){ + return ALG_ERR_BAD_INPUT_DATA; + } + if(head->next == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + t = head->next; + + while(t != NULL) { + if(t->data == target_data) { + t->data = new_data; + return ALG_OK; + } + } + + return ALG_ERR_NO_THIS_POINT; +} \ No newline at end of file -- Gitee From bfeb97a4a9059f1761187b44160d951544e0c92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=97=E7=86=8A?= <1248825327@qq.com> Date: Wed, 4 Aug 2021 10:12:17 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8C=89=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E6=9B=B4=E6=96=B0?= 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 +- yonglin_zhang/C/link_list/src/update.c | 25 +++++++++++++++++++ 2 files changed, 26 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 dce0207..204cca9 100644 --- a/yonglin_zhang/C/link_list/include/link_list.h +++ b/yonglin_zhang/C/link_list/include/link_list.h @@ -235,7 +235,7 @@ int update_data_x(node *head, DATA_TYPE target_data, DATA_TYPE new_data); * * \return #ALG_OK 操作成功。 */ -int update_pos_x(); +int update_pos_x(node *head, int pos, DATA_TYPE new_data); #ifdef __cplusplus diff --git a/yonglin_zhang/C/link_list/src/update.c b/yonglin_zhang/C/link_list/src/update.c index c0dbfd3..f163494 100644 --- a/yonglin_zhang/C/link_list/src/update.c +++ b/yonglin_zhang/C/link_list/src/update.c @@ -24,4 +24,29 @@ int update_data_x(node *head, DATA_TYPE target_data, DATA_TYPE new_data) } return ALG_ERR_NO_THIS_POINT; +} + +int update_pos_x(node *head, int pos, DATA_TYPE new_data) +{ + node *t = NULL; + int counter = 1; + + if(head == NULL || pos <= 0) { + return ALG_ERR_BAD_INPUT_DATA; + } + if(head->next == NULL) { + return ALG_ERR_EMPTY_LIST; + } + + t = head->next; + + while(t != NULL) { + if(counter == pos) { + t->data = new_data; + return ALG_OK; + } + t = t->next; + } + + return ALG_ERR_POS_NOT_IN_RANGE; } \ No newline at end of file -- Gitee From 7afd6721c6413754108203976eaf2af06e107335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8B=97=E7=86=8A?= <1248825327@qq.com> Date: Wed, 4 Aug 2021 10:12:36 +0800 Subject: [PATCH 11/11] =?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/update.c | 1 + 1 file changed, 1 insertion(+) diff --git a/yonglin_zhang/C/link_list/src/update.c b/yonglin_zhang/C/link_list/src/update.c index f163494..7b80666 100644 --- a/yonglin_zhang/C/link_list/src/update.c +++ b/yonglin_zhang/C/link_list/src/update.c @@ -21,6 +21,7 @@ int update_data_x(node *head, DATA_TYPE target_data, DATA_TYPE new_data) t->data = new_data; return ALG_OK; } + t = t->next; } return ALG_ERR_NO_THIS_POINT; -- Gitee