style(codes/c): update comment format
This commit is contained in:
parent
be2d109c5b
commit
78d7d07bd9
@ -7,13 +7,15 @@
|
|||||||
#include "../include/include.h"
|
#include "../include/include.h"
|
||||||
|
|
||||||
/* 在链表的结点 n0 之后插入结点 P */
|
/* 在链表的结点 n0 之后插入结点 P */
|
||||||
void insertNode(ListNode* n0, ListNode* P) {
|
void insert(ListNode* n0, ListNode* P) {
|
||||||
ListNode *n1 = n0->next;
|
ListNode *n1 = n0->next;
|
||||||
n0->next = P;
|
n0->next = P;
|
||||||
P->next = n1;
|
P->next = n1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 删除链表的结点 n0 之后的首个结点 */
|
/* 删除链表的结点 n0 之后的首个结点 */
|
||||||
|
/* Keep Sample, 受 c 语言特性限制,removeNode 无法更改为 remove,
|
||||||
|
详见 https://github.com/krahets/hello-algo/pull/244#discussion_r1067863888 */
|
||||||
void removeNode(ListNode* n0) {
|
void removeNode(ListNode* n0) {
|
||||||
if (!n0->next)
|
if (!n0->next)
|
||||||
return;
|
return;
|
||||||
@ -26,7 +28,7 @@ void removeNode(ListNode* n0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 访问链表中索引为 index 的结点 */
|
/* 访问链表中索引为 index 的结点 */
|
||||||
ListNode* accessNode(ListNode* head, int index) {
|
ListNode* access(ListNode* head, int index) {
|
||||||
while (head && head->next && index) {
|
while (head && head->next && index) {
|
||||||
head = head->next;
|
head = head->next;
|
||||||
index--;
|
index--;
|
||||||
@ -35,7 +37,7 @@ ListNode* accessNode(ListNode* head, int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 在链表中查找值为 target 的首个结点 */
|
/* 在链表中查找值为 target 的首个结点 */
|
||||||
int findNode(ListNode* head, int target) {
|
int find(ListNode* head, int target) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (head) {
|
while (head) {
|
||||||
if (head->val == target)
|
if (head->val == target)
|
||||||
@ -65,7 +67,7 @@ int main() {
|
|||||||
printLinkedList(n0);
|
printLinkedList(n0);
|
||||||
|
|
||||||
/* 插入结点 */
|
/* 插入结点 */
|
||||||
insertNode(n0, newListNode(0));
|
insert(n0, newListNode(0));
|
||||||
printf("插入结点后的链表为\r\n");
|
printf("插入结点后的链表为\r\n");
|
||||||
printLinkedList(n0);
|
printLinkedList(n0);
|
||||||
|
|
||||||
@ -75,11 +77,11 @@ int main() {
|
|||||||
printLinkedList(n0);
|
printLinkedList(n0);
|
||||||
|
|
||||||
/* 访问结点 */
|
/* 访问结点 */
|
||||||
ListNode* node = accessNode(n0, 3);
|
ListNode* node = access(n0, 3);
|
||||||
printf("链表中索引 3 处的结点的值 = %d\r\n", node->val);
|
printf("链表中索引 3 处的结点的值 = %d\r\n", node->val);
|
||||||
|
|
||||||
/* 查找结点 */
|
/* 查找结点 */
|
||||||
int index = findNode(n0, 2);
|
int index = find(n0, 2);
|
||||||
printf("链表中值为 2 的结点的索引 = %d\r\n", index);
|
printf("链表中值为 2 的结点的索引 = %d\r\n", index);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user