Add TypeScript code and docs to Chapter of Heap (#349)

* Add TypeScript code and docs to Chapter of Heap

* Update my_heap.ts

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
Justin Tse
2023-02-07 20:50:54 +08:00
committed by GitHub
parent 7666632d0c
commit 1cc9cecebe
3 changed files with 266 additions and 6 deletions
+19 -3
View File
@@ -4,8 +4,8 @@
* Author: Justin (xiefahit@gmail.com)
*/
import { ListNode } from './ListNode';
import { TreeNode } from './TreeNode';
import { ListNode } from "./ListNode";
import { TreeNode, arrToTree } from "./TreeNode";
/**
* Print a linked list
@@ -93,4 +93,20 @@ function showTrunks(p: Trunk | null) {
// restart the vscode
}
export { printLinkedList, printTree };
/**
* Print a heap
* @param arr
*/
function printHeap(arr: number[]): void {
console.log("堆的数组表示:");
console.log(arr);
console.log("堆的树状表示:");
const root = arrToTree(arr);
printTree(root);
}
export {
printLinkedList,
printTree,
printHeap
};