mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-24 02:03:10 +08:00
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:
@ -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,
|
||||
};
|
||||
|
Reference in New Issue
Block a user