Fix bugs and harmonize the code comments (#1199)

* Fix the comment in array_deque.go

* Fix the comment in bucket_sort.c

* Translate the Java code comments to Chinese

* Bug fixes

* 二分查找 -> 二分搜尋

* Harmonize comments in `utils` between multiple programming languages
This commit is contained in:
Yudong Jin
2024-03-31 03:06:41 +08:00
committed by GitHub
parent cfe8281aee
commit 034ee65e9a
35 changed files with 133 additions and 271 deletions

View File

@@ -11,9 +11,6 @@ void testListNode() {
int size = sizeof(nums) / sizeof(int);
ListNode *head = arrToLinkedList(nums, size);
printLinkedList(head);
ListNode *node = getListNode(head, 5);
printf("find node: %d\n", node->val);
}
void testTreeNode() {

View File

@@ -26,7 +26,7 @@ ListNode *newListNode(int val) {
return node;
}
/* Generate a linked list with an array */
/* 将数组反序列化为链表 */
ListNode *arrToLinkedList(const int *arr, size_t size) {
if (size <= 0) {
return NULL;
@@ -41,15 +41,7 @@ ListNode *arrToLinkedList(const int *arr, size_t size) {
return dummy->next;
}
/* Get a list node with specific value from a linked list */
ListNode *getListNode(ListNode *head, int val) {
while (head != NULL && head->val != val) {
head = head->next;
}
return head;
}
/* Free the memory allocated to a linked list */
/* 释放分配给链表的内存空间 */
void freeMemoryLinkedList(ListNode *cur) {
// 释放内存
ListNode *pre;

View File

@@ -18,7 +18,7 @@
extern "C" {
#endif
/* Print an Array */
/* 打印数组 */
void printArray(int arr[], int size) {
if (arr == NULL || size == 0) {
printf("[]");
@@ -31,7 +31,7 @@ void printArray(int arr[], int size) {
printf("%d]\n", arr[size - 1]);
}
/* Print an Array */
/* 打印数组 */
void printArrayFloat(float arr[], int size) {
if (arr == NULL || size == 0) {
printf("[]");
@@ -44,7 +44,7 @@ void printArrayFloat(float arr[], int size) {
printf("%.2f]\n", arr[size - 1]);
}
/* Print a linked list */
/* 打印链表 */
void printLinkedList(ListNode *node) {
if (node == NULL) {
return;
@@ -69,7 +69,6 @@ Trunk *newTrunk(Trunk *prev, char *str) {
return trunk;
}
/* Helper function to print branches of the binary tree */
void showTrunks(Trunk *trunk) {
if (trunk == NULL) {
return;
@@ -78,7 +77,11 @@ void showTrunks(Trunk *trunk) {
printf("%s", trunk->str);
}
/* Help to print a binary tree, hide more details */
/**
* 打印二叉树
* This tree printer is borrowed from TECHIE DELIGHT
* https://www.techiedelight.com/c-program-print-binary-tree/
*/
void printTreeHelper(TreeNode *node, Trunk *prev, bool isRight) {
if (node == NULL) {
return;
@@ -106,12 +109,12 @@ void printTreeHelper(TreeNode *node, Trunk *prev, bool isRight) {
printTreeHelper(node->left, trunk, false);
}
/* Print a binary tree */
/* 打印二叉树 */
void printTree(TreeNode *root) {
printTreeHelper(root, NULL, false);
}
/* Print a Heap */
/* 打印堆 */
void printHeap(int arr[], int size) {
TreeNode *root;
printf("堆的数组表示:");