mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +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,9 +4,7 @@
|
||||
* Author: Justin (xiefahit@gmail.com)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Definition for a singly-linked list node
|
||||
*/
|
||||
/* 链表节点 */
|
||||
class ListNode {
|
||||
val: number;
|
||||
next: ListNode | null;
|
||||
@ -16,11 +14,7 @@ class ListNode {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a linked list with an array
|
||||
* @param arr
|
||||
* @return
|
||||
*/
|
||||
/* 将数组反序列化为链表 */
|
||||
function arrToLinkedList(arr: number[]): ListNode | null {
|
||||
const dum: ListNode = new ListNode(0);
|
||||
let head = dum;
|
||||
@ -31,17 +25,4 @@ function arrToLinkedList(arr: number[]): ListNode | null {
|
||||
return dum.next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list node with specific value from a linked list
|
||||
* @param head
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
function getListNode(head: ListNode | null, val: number): ListNode | null {
|
||||
while (head !== null && head.val !== val) {
|
||||
head = head.next;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
export { ListNode, arrToLinkedList, getListNode };
|
||||
export { ListNode, arrToLinkedList };
|
||||
|
||||
@ -7,10 +7,7 @@
|
||||
import { ListNode } from './ListNode';
|
||||
import { TreeNode, arrToTree } from './TreeNode';
|
||||
|
||||
/**
|
||||
* Print a linked list
|
||||
* @param head
|
||||
*/
|
||||
/* 打印链表 */
|
||||
function printLinkedList(head: ListNode | null): void {
|
||||
const list: string[] = [];
|
||||
while (head !== null) {
|
||||
@ -31,21 +28,15 @@ class Trunk {
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface of the tree printer
|
||||
* 打印二叉树
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
* @param root
|
||||
*/
|
||||
function printTree(root: TreeNode | null) {
|
||||
printTreeHelper(root, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a binary tree
|
||||
* @param root
|
||||
* @param prev
|
||||
* @param isRight
|
||||
*/
|
||||
/* 打印二叉树 */
|
||||
function printTreeHelper(
|
||||
root: TreeNode | null,
|
||||
prev: Trunk | null,
|
||||
@ -81,10 +72,6 @@ function printTreeHelper(
|
||||
printTreeHelper(root.left, trunk, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to print branches of the binary tree
|
||||
* @param p
|
||||
*/
|
||||
function showTrunks(p: Trunk | null) {
|
||||
if (p === null) {
|
||||
return;
|
||||
@ -97,10 +84,7 @@ function showTrunks(p: Trunk | null) {
|
||||
// restart the vscode
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a heap
|
||||
* @param arr
|
||||
*/
|
||||
/* 打印堆 */
|
||||
function printHeap(arr: number[]): void {
|
||||
console.log('堆的数组表示:');
|
||||
console.log(arr);
|
||||
|
||||
@ -4,9 +4,7 @@
|
||||
* Author: Justin (xiefahit@gmail.com)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Definition for a binary tree node.
|
||||
*/
|
||||
/* 二叉树节点 */
|
||||
class TreeNode {
|
||||
val: number; // 节点值
|
||||
height: number; // 节点高度
|
||||
@ -25,11 +23,7 @@ class TreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a binary tree given an array
|
||||
* @param arr
|
||||
* @return
|
||||
*/
|
||||
/* 将数组反序列化为二叉树 */
|
||||
function arrToTree(arr: (number | null)[], i: number = 0): TreeNode | null {
|
||||
if (i < 0 || i >= arr.length || arr[i] === null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user