mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
Fomrat the JS and TS codes with prettier.
This commit is contained in:
@ -11,8 +11,8 @@ class ListNode {
|
||||
val;
|
||||
next;
|
||||
constructor(val, next) {
|
||||
this.val = (val === undefined ? 0 : val);
|
||||
this.next = (next === undefined ? null : next);
|
||||
this.val = val === undefined ? 0 : val;
|
||||
this.next = next === undefined ? null : next;
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,5 +47,5 @@ function getListNode(head, val) {
|
||||
module.exports = {
|
||||
ListNode,
|
||||
arrToLinkedList,
|
||||
getListNode
|
||||
getListNode,
|
||||
};
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
* Author: IsChristina (christinaxia77@foxmail.com)
|
||||
*/
|
||||
|
||||
const { arrToTree } = require("./TreeNode");
|
||||
const { arrToTree } = require('./TreeNode');
|
||||
|
||||
/**
|
||||
* Print a linked list
|
||||
@ -16,7 +16,7 @@ function printLinkedList(head) {
|
||||
list.push(head.val.toString());
|
||||
head = head.next;
|
||||
}
|
||||
console.log(list.join(" -> "));
|
||||
console.log(list.join(' -> '));
|
||||
}
|
||||
|
||||
function Trunk(prev, str) {
|
||||
@ -45,28 +45,28 @@ function printTree(root, prev, isLeft) {
|
||||
return;
|
||||
}
|
||||
|
||||
let prev_str = " ";
|
||||
let prev_str = ' ';
|
||||
let trunk = new Trunk(prev, prev_str);
|
||||
|
||||
printTree(root.right, trunk, true);
|
||||
|
||||
if (!prev) {
|
||||
trunk.str = "———";
|
||||
trunk.str = '———';
|
||||
} else if (isLeft) {
|
||||
trunk.str = "/———";
|
||||
prev_str = " |";
|
||||
trunk.str = '/———';
|
||||
prev_str = ' |';
|
||||
} else {
|
||||
trunk.str = "\\———";
|
||||
trunk.str = '\\———';
|
||||
prev.str = prev_str;
|
||||
}
|
||||
|
||||
showTrunks(trunk);
|
||||
console.log(" " + root.val);
|
||||
console.log(' ' + root.val);
|
||||
|
||||
if (prev) {
|
||||
prev.str = prev_str;
|
||||
}
|
||||
trunk.str = " |";
|
||||
trunk.str = ' |';
|
||||
|
||||
printTree(root.left, trunk, false);
|
||||
}
|
||||
@ -89,14 +89,14 @@ function showTrunks(p) {
|
||||
* @param arr
|
||||
*/
|
||||
function printHeap(arr) {
|
||||
console.log("堆的数组表示:");
|
||||
console.log('堆的数组表示:');
|
||||
console.log(arr);
|
||||
console.log("堆的树状表示:");
|
||||
console.log('堆的树状表示:');
|
||||
printTree(arrToTree(arr));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
printLinkedList,
|
||||
printTree,
|
||||
printHeap
|
||||
printHeap,
|
||||
};
|
||||
|
||||
@ -50,5 +50,5 @@ function arrToTree(arr) {
|
||||
|
||||
module.exports = {
|
||||
TreeNode,
|
||||
arrToTree
|
||||
arrToTree,
|
||||
};
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
* Author: Zhuo Qinyue (1403450829@qq.com)
|
||||
*/
|
||||
|
||||
|
||||
/* 顶点类 */
|
||||
class Vertex {
|
||||
val;
|
||||
@ -32,5 +31,5 @@ class Vertex {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Vertex
|
||||
Vertex,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user