diff --git a/heapsort.dart b/heapsort.dart new file mode 100644 index 0000000..801695e --- /dev/null +++ b/heapsort.dart @@ -0,0 +1,17 @@ +import 'heap.dart'; + +List heapsort>(List list) { + // 1 + final heap = Heap( + elements: list.toList(), + priority: Priority.min, + ); + // 2 + final sorted = []; + // 3 + while (!heap.isEmpty) { + final value = heap.remove(); + sorted.add(value!); + } + return sorted; +}