mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-03 02:54:22 +00:00
Fomrat the JS and TS codes with prettier.
This commit is contained in:
@@ -44,8 +44,4 @@ function getListNode(head: ListNode | null, val: number): ListNode | null {
|
||||
return head;
|
||||
}
|
||||
|
||||
export {
|
||||
ListNode,
|
||||
arrToLinkedList,
|
||||
getListNode
|
||||
};
|
||||
export { ListNode, arrToLinkedList, getListNode };
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* Author: Zhuo Qinyue (1403450829@qq.com)
|
||||
*/
|
||||
|
||||
|
||||
/* 顶点类 */
|
||||
class Vertex {
|
||||
val: number;
|
||||
@@ -31,6 +30,4 @@ class Vertex {
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Vertex
|
||||
};
|
||||
export { Vertex };
|
||||
|
||||
Reference in New Issue
Block a user