From f788a478abb4b936448d33f31ede5cbf8b839346 Mon Sep 17 00:00:00 2001 From: SHEIK RIFAZ ALI Date: Sun, 30 Oct 2022 23:31:26 +0530 Subject: [PATCH] heap sort using sort --- heapsort.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 heapsort.dart 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; +}