From 78d7d07bd9cfc4308b50cc756b0743c9e0d0367c Mon Sep 17 00:00:00 2001 From: Gonglja Date: Fri, 13 Jan 2023 06:01:21 +0800 Subject: [PATCH] style(codes/c): update comment format --- codes/c/chapter_array_and_linkedlist/linked_list.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/codes/c/chapter_array_and_linkedlist/linked_list.c b/codes/c/chapter_array_and_linkedlist/linked_list.c index 5ce7cf4c..8228c48c 100644 --- a/codes/c/chapter_array_and_linkedlist/linked_list.c +++ b/codes/c/chapter_array_and_linkedlist/linked_list.c @@ -7,13 +7,15 @@ #include "../include/include.h" /* 在链表的结点 n0 之后插入结点 P */ -void insertNode(ListNode* n0, ListNode* P) { +void insert(ListNode* n0, ListNode* P) { ListNode *n1 = n0->next; n0->next = P; P->next = n1; } /* 删除链表的结点 n0 之后的首个结点 */ +/* Keep Sample, 受 c 语言特性限制,removeNode 无法更改为 remove, + 详见 https://github.com/krahets/hello-algo/pull/244#discussion_r1067863888 */ void removeNode(ListNode* n0) { if (!n0->next) return; @@ -26,7 +28,7 @@ void removeNode(ListNode* n0) { } /* 访问链表中索引为 index 的结点 */ -ListNode* accessNode(ListNode* head, int index) { +ListNode* access(ListNode* head, int index) { while (head && head->next && index) { head = head->next; index--; @@ -35,7 +37,7 @@ ListNode* accessNode(ListNode* head, int index) { } /* 在链表中查找值为 target 的首个结点 */ -int findNode(ListNode* head, int target) { +int find(ListNode* head, int target) { int index = 0; while (head) { if (head->val == target) @@ -65,7 +67,7 @@ int main() { printLinkedList(n0); /* 插入结点 */ - insertNode(n0, newListNode(0)); + insert(n0, newListNode(0)); printf("插入结点后的链表为\r\n"); printLinkedList(n0); @@ -75,11 +77,11 @@ int main() { printLinkedList(n0); /* 访问结点 */ - ListNode* node = accessNode(n0, 3); + ListNode* node = access(n0, 3); printf("链表中索引 3 处的结点的值 = %d\r\n", node->val); /* 查找结点 */ - int index = findNode(n0, 2); + int index = find(n0, 2); printf("链表中值为 2 的结点的索引 = %d\r\n", index); return 0;