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:
@ -6,7 +6,7 @@
|
||||
|
||||
package utils;
|
||||
|
||||
/* Definition for a singly-linked list node */
|
||||
/* 链表节点 */
|
||||
public class ListNode {
|
||||
public int val;
|
||||
public ListNode next;
|
||||
@ -15,7 +15,7 @@ public class ListNode {
|
||||
val = x;
|
||||
}
|
||||
|
||||
/* Generate a linked list with an array */
|
||||
/* 将列表反序列化为链表 */
|
||||
public static ListNode arrToLinkedList(int[] arr) {
|
||||
ListNode dum = new ListNode(0);
|
||||
ListNode head = dum;
|
||||
@ -25,12 +25,4 @@ public class ListNode {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,8 +19,7 @@ class Trunk {
|
||||
};
|
||||
|
||||
public class PrintUtil {
|
||||
|
||||
/* Print a matrix (Array) */
|
||||
/* 打印矩阵(Array) */
|
||||
public static <T> void printMatrix(T[][] matrix) {
|
||||
System.out.println("[");
|
||||
for (T[] row : matrix) {
|
||||
@ -29,7 +28,7 @@ public class PrintUtil {
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
/* Print a matrix (List) */
|
||||
/* 打印矩阵(List) */
|
||||
public static <T> void printMatrix(List<List<T>> matrix) {
|
||||
System.out.println("[");
|
||||
for (List<T> row : matrix) {
|
||||
@ -38,7 +37,7 @@ public class PrintUtil {
|
||||
System.out.println("]");
|
||||
}
|
||||
|
||||
/* Print a linked list */
|
||||
/* 打印链表 */
|
||||
public static void printLinkedList(ListNode head) {
|
||||
List<String> list = new ArrayList<>();
|
||||
while (head != null) {
|
||||
@ -48,16 +47,16 @@ public class PrintUtil {
|
||||
System.out.println(String.join(" -> ", list));
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface of the tree printer
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
/* 打印二叉树 */
|
||||
public static void printTree(TreeNode root) {
|
||||
printTree(root, null, false);
|
||||
}
|
||||
|
||||
/* Print a binary tree */
|
||||
/**
|
||||
* 打印二叉树
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
public static void printTree(TreeNode root, Trunk prev, boolean isRight) {
|
||||
if (root == null) {
|
||||
return;
|
||||
@ -89,7 +88,6 @@ public 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;
|
||||
@ -99,14 +97,14 @@ public class PrintUtil {
|
||||
System.out.print(p.str);
|
||||
}
|
||||
|
||||
/* Print a hash map */
|
||||
/* 打印哈希表 */
|
||||
public static <K, V> void printHashMap(Map<K, V> map) {
|
||||
for (Map.Entry<K, V> kv : map.entrySet()) {
|
||||
System.out.println(kv.getKey() + " -> " + kv.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/* Print a heap (PriorityQueue) */
|
||||
/* 打印堆(优先队列) */
|
||||
public static void printHeap(Queue<Integer> queue) {
|
||||
List<Integer> list = new ArrayList<>(queue);
|
||||
System.out.print("堆的数组表示:");
|
||||
|
||||
Reference in New Issue
Block a user