mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-11 16:32:00 +08:00
Retranslate the complete English edition from Simplified Chinese (#2010)
* Retranslate the complete English edition from Simplified Chinese * Polish three English explanations after reader-focused review
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
/* Linked list node */
|
||||
class ListNode {
|
||||
val; // Node value
|
||||
next; // Reference (pointer) to next node
|
||||
next; // Reference (pointer) to the next node
|
||||
constructor(val, next) {
|
||||
this.val = val === undefined ? 0 : val;
|
||||
this.next = next === undefined ? null : next;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
const { arrToTree } = require('./TreeNode');
|
||||
|
||||
/* Print linked list */
|
||||
/* Print a linked list */
|
||||
function printLinkedList(head) {
|
||||
let list = [];
|
||||
while (head !== null) {
|
||||
@@ -22,7 +22,7 @@ function Trunk(prev, str) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print binary tree
|
||||
* Print the binary tree
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
@@ -30,7 +30,7 @@ function printTree(root) {
|
||||
printTree(root, null, false);
|
||||
}
|
||||
|
||||
/* Print binary tree */
|
||||
/* Print the binary tree */
|
||||
function printTree(root, prev, isRight) {
|
||||
if (root === null) {
|
||||
return;
|
||||
@@ -71,11 +71,11 @@ function showTrunks(p) {
|
||||
process.stdout.write(p.str);
|
||||
}
|
||||
|
||||
/* Print heap */
|
||||
/* Print a heap */
|
||||
function printHeap(arr) {
|
||||
console.log('Heap array representation:');
|
||||
console.log('Array representation of the heap:');
|
||||
console.log(arr);
|
||||
console.log('Heap tree representation:');
|
||||
console.log('Tree representation of the heap:');
|
||||
printTree(arrToTree(arr));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
/* Binary tree node */
|
||||
class TreeNode {
|
||||
val; // Node value
|
||||
left; // Left child pointer
|
||||
right; // Right child pointer
|
||||
height; // Node height
|
||||
left; // Pointer to the left child
|
||||
right; // Pointer to the right child
|
||||
height; //Node height
|
||||
constructor(val, left, right, height) {
|
||||
this.val = val === undefined ? 0 : val;
|
||||
this.left = left === undefined ? null : left;
|
||||
@@ -18,7 +18,7 @@ class TreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
/* Deserialize array to binary tree */
|
||||
/* Deserialize an array into a binary tree */
|
||||
function arrToTree(arr, i = 0) {
|
||||
if (i < 0 || i >= arr.length || arr[i] === null) {
|
||||
return null;
|
||||
|
||||
@@ -11,7 +11,7 @@ class Vertex {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
/* Input value list vals, return vertex list vets */
|
||||
/* Given the list of values vals, return the list of vertices vets */
|
||||
static valsToVets(vals) {
|
||||
const vets = [];
|
||||
for (let i = 0; i < vals.length; i++) {
|
||||
@@ -20,7 +20,7 @@ class Vertex {
|
||||
return vets;
|
||||
}
|
||||
|
||||
/* Input vertex list vets, return value list vals */
|
||||
/* Given the list of vertices vets, return the list of values vals */
|
||||
static vetsToVals(vets) {
|
||||
const vals = [];
|
||||
for (const vet of vets) {
|
||||
|
||||
Reference in New Issue
Block a user