Fomrat the JS and TS codes with prettier.

This commit is contained in:
krahets
2023-04-17 21:58:11 +08:00
parent 9a98ff8a5e
commit c4ea4e39f3
68 changed files with 634 additions and 510 deletions

View File

@ -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,
};

View File

@ -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,
};

View File

@ -50,5 +50,5 @@ function arrToTree(arr) {
module.exports = {
TreeNode,
arrToTree
arrToTree,
};

View File

@ -4,7 +4,6 @@
* Author: Zhuo Qinyue (1403450829@qq.com)
*/
/* 顶点类 */
class Vertex {
val;
@ -32,5 +31,5 @@ class Vertex {
}
module.exports = {
Vertex
Vertex,
};