mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
feat: add dart code for chapter_heap (#454)
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
* Created Time: 2023-01-23
|
||||
* Author: Jefferson (JeffersonHuang77@gmail.com)
|
||||
*/
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'list_node.dart';
|
||||
@ -25,12 +26,6 @@ void printLinkedList(ListNode? head) {
|
||||
|
||||
print(list.join(' -> '));
|
||||
}
|
||||
/*
|
||||
* Print a binary tree
|
||||
* @param root
|
||||
* @param prev
|
||||
* @param isLeft
|
||||
*/
|
||||
|
||||
void printTree(TreeNode? root, [Trunk? prev = null, bool isLeft = false]) {
|
||||
if (root == null) {
|
||||
@ -70,3 +65,10 @@ void showTrunks(Trunk? p) {
|
||||
showTrunks(p.prev);
|
||||
stdout.write(p.str);
|
||||
}
|
||||
|
||||
void printHeap(List<int> heap) {
|
||||
print("堆的数组表示:$heap");
|
||||
print("堆的树状表示:");
|
||||
TreeNode? root = listToTree(heap);
|
||||
printTree(root);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user