mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
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:
@ -4,12 +4,12 @@
|
||||
|
||||
namespace hello_algo.utils;
|
||||
|
||||
/* Definition for a singly-linked list node */
|
||||
/* 链表节点 */
|
||||
public class ListNode(int x) {
|
||||
public int val = x;
|
||||
public ListNode? next;
|
||||
|
||||
/* Generate a linked list with an array */
|
||||
/* 将数组反序列化为链表 */
|
||||
public static ListNode? ArrToLinkedList(int[] arr) {
|
||||
ListNode dum = new(0);
|
||||
ListNode head = dum;
|
||||
@ -20,14 +20,6 @@ public class ListNode(int x) {
|
||||
return dum.next;
|
||||
}
|
||||
|
||||
/* Get a list node with specific value from a linked list */
|
||||
public static ListNode? GetListNode(ListNode? head, int val) {
|
||||
while (head != null && head.val != val) {
|
||||
head = head.next;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
public override string? ToString() {
|
||||
List<string> list = [];
|
||||
var head = this;
|
||||
|
||||
@ -12,7 +12,7 @@ public class Trunk(Trunk? prev, string str) {
|
||||
};
|
||||
|
||||
public static class PrintUtil {
|
||||
/* Print a list */
|
||||
/* 打印列表 */
|
||||
public static void PrintList<T>(IList<T> list) {
|
||||
Console.WriteLine("[" + string.Join(", ", list) + "]");
|
||||
}
|
||||
@ -21,7 +21,7 @@ public static class PrintUtil {
|
||||
return $"[ {string.Join(", ", list.Select(x => x?.ToString() ?? "null"))} ]";
|
||||
}
|
||||
|
||||
/* Print a matrix (Array) */
|
||||
/* 打印矩阵 (Array) */
|
||||
public static void PrintMatrix<T>(T[][] matrix) {
|
||||
Console.WriteLine("[");
|
||||
foreach (T[] row in matrix) {
|
||||
@ -30,7 +30,7 @@ public static class PrintUtil {
|
||||
Console.WriteLine("]");
|
||||
}
|
||||
|
||||
/* Print a matrix (List) */
|
||||
/* 打印矩阵 (List) */
|
||||
public static void PrintMatrix<T>(List<List<T>> matrix) {
|
||||
Console.WriteLine("[");
|
||||
foreach (List<T> row in matrix) {
|
||||
@ -39,7 +39,7 @@ public static class PrintUtil {
|
||||
Console.WriteLine("]");
|
||||
}
|
||||
|
||||
/* Print a linked list */
|
||||
/* 打印链表 */
|
||||
public static void PrintLinkedList(ListNode? head) {
|
||||
List<string> list = [];
|
||||
while (head != null) {
|
||||
@ -50,7 +50,7 @@ public static class PrintUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface of the tree printer
|
||||
* 打印二叉树
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
@ -58,7 +58,7 @@ public static class PrintUtil {
|
||||
PrintTree(root, null, false);
|
||||
}
|
||||
|
||||
/* Print a binary tree */
|
||||
/* 打印二叉树 */
|
||||
public static void PrintTree(TreeNode? root, Trunk? prev, bool isRight) {
|
||||
if (root == null) {
|
||||
return;
|
||||
@ -90,7 +90,6 @@ public static class PrintUtil {
|
||||
PrintTree(root.left, trunk, false);
|
||||
}
|
||||
|
||||
/* Helper function to print branches of the binary tree */
|
||||
public static void ShowTrunks(Trunk? p) {
|
||||
if (p == null) {
|
||||
return;
|
||||
@ -100,14 +99,14 @@ public static class PrintUtil {
|
||||
Console.Write(p.str);
|
||||
}
|
||||
|
||||
/* Print a hash map */
|
||||
/* 打印哈希表 */
|
||||
public static void PrintHashMap<K, V>(Dictionary<K, V> map) where K : notnull {
|
||||
foreach (var kv in map.Keys) {
|
||||
Console.WriteLine(kv.ToString() + " -> " + map[kv]?.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/* Print a heap */
|
||||
/* 打印堆 */
|
||||
public static void PrintHeap(Queue<int> queue) {
|
||||
Console.Write("堆的数组表示:");
|
||||
List<int> list = [.. queue];
|
||||
@ -117,7 +116,7 @@ public static class PrintUtil {
|
||||
PrintTree(tree);
|
||||
}
|
||||
|
||||
/* Print a PriorityQueue */
|
||||
/* 打印优先队列 */
|
||||
public static void PrintHeap(PriorityQueue<int, int> queue) {
|
||||
var newQueue = new PriorityQueue<int, int>(queue.UnorderedItems, queue.Comparer);
|
||||
Console.Write("堆的数组表示:");
|
||||
|
||||
Reference in New Issue
Block a user