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
+1 -5
View File
@@ -44,8 +44,4 @@ function getListNode(head: ListNode | null, val: number): ListNode | null {
return head;
}
export {
ListNode,
arrToLinkedList,
getListNode
};
export { ListNode, arrToLinkedList, getListNode };
+10 -10
View File
@@ -4,8 +4,8 @@
* Author: Justin (xiefahit@gmail.com)
*/
import { ListNode } from "./ListNode";
import { TreeNode, arrToTree } from "./TreeNode";
import { ListNode } from './ListNode';
import { TreeNode, arrToTree } from './TreeNode';
/**
* Print a linked list
@@ -46,7 +46,11 @@ function printTree(root: TreeNode | null) {
* @param prev
* @param isLeft
*/
function printTreeHelper(root: TreeNode | null, prev: Trunk | null, isLeft: boolean) {
function printTreeHelper(
root: TreeNode | null,
prev: Trunk | null,
isLeft: boolean
) {
if (root === null) {
return;
}
@@ -98,15 +102,11 @@ function showTrunks(p: Trunk | null) {
* @param arr
*/
function printHeap(arr: number[]): void {
console.log("堆的数组表示:");
console.log('堆的数组表示:');
console.log(arr);
console.log("堆的树状表示:");
console.log('堆的树状表示:');
const root = arrToTree(arr);
printTree(root);
}
export {
printLinkedList,
printTree,
printHeap
};
export { printLinkedList, printTree, printHeap };
+13 -11
View File
@@ -8,15 +8,20 @@
* Definition for a binary tree node.
*/
class TreeNode {
val: number; // 节点值
height: number; // 节点高度
left: TreeNode | null; // 左子节点指针
val: number; // 节点值
height: number; // 节点高度
left: TreeNode | null; // 左子节点指针
right: TreeNode | null; // 右子节点指针
constructor(val?: number, height?: number, left?: TreeNode | null, right?: TreeNode | null) {
constructor(
val?: number,
height?: number,
left?: TreeNode | null,
right?: TreeNode | null
) {
this.val = val === undefined ? 0 : val;
this.height = height === undefined ? 0 : height;
this.left = left === undefined ? null : left;
this.right = right === undefined ? null : right;
this.height = height === undefined ? 0 : height;
this.left = left === undefined ? null : left;
this.right = right === undefined ? null : right;
}
}
@@ -49,7 +54,4 @@ function arrToTree(arr: (number | null)[]): TreeNode | null {
return root;
}
export {
TreeNode,
arrToTree
};
export { TreeNode, arrToTree };
+1 -4
View File
@@ -4,7 +4,6 @@
* Author: Zhuo Qinyue (1403450829@qq.com)
*/
/* 顶点类 */
class Vertex {
val: number;
@@ -31,6 +30,4 @@ class Vertex {
}
}
export {
Vertex
};
export { Vertex };