summaryrefslogtreecommitdiff
path: root/lib/data_structures
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-10-12 21:16:07 -0600
committermo khan <mo@mokhan.ca>2013-10-12 21:16:07 -0600
commitf199bfd55cc81bcdc4ae23b8024d41f9476546c4 (patch)
treec78a18ee13b3681f7f13fbf7a9cbfc756ff36ea2 /lib/data_structures
parent4dc38797d9ff4957c48c1b6d3b45ff36708d275a (diff)
start to build a min heap.
Diffstat (limited to 'lib/data_structures')
-rw-r--r--lib/data_structures/min_heap.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/data_structures/min_heap.rb b/lib/data_structures/min_heap.rb
new file mode 100644
index 0000000..3f90dc3
--- /dev/null
+++ b/lib/data_structures/min_heap.rb
@@ -0,0 +1,14 @@
+class MinHeap
+ def initialize(items = [])
+ @items = items
+ @items.sort!
+ end
+
+ def min
+ @items.shift
+ end
+
+ def empty?
+ @items.empty?
+ end
+end