Add heap part js code (#339)

* Add heap part js code

* Update heap.md

* Update heap.md

* Format the code style and fix a bug.

* and fix the style in heap.md

* fix the style

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
Leo.Cai
2023-02-07 20:48:54 +08:00
committed by GitHub
parent 8f512c2840
commit 7666632d0c
3 changed files with 270 additions and 10 deletions

View File

@ -4,6 +4,8 @@
* Author: IsChristina (christinaxia77@foxmail.com)
*/
const { arrToTree } = require("./TreeNode");
/**
* Print a linked list
* @param head
@ -82,7 +84,19 @@ function showTrunks(p) {
process.stdout.write(p.str);
}
/**
* Print a heap
* @param arr
*/
function printHeap(arr) {
console.log("堆的数组表示:");
console.log(arr);
console.log("堆的树状表示:");
printTree(arrToTree(arr));
}
module.exports = {
printLinkedList,
printTree
}
printTree,
printHeap,
};