Class: Heap::BinaryHeap::MinHeap
Overview
Binary Heap with min root
Instance Attribute Summary
Attributes inherited from BinaryHeap
#elements
Instance Method Summary
collapse
Methods inherited from BinaryHeap
#add, #count, #initialize
Instance Method Details
5
6
7
|
# File 'lib/Heap/binary_heap/binary_heap_min.rb', line 5
def
@elements[0]
end
|
9
10
11
12
13
14
|
# File 'lib/Heap/binary_heap/binary_heap_min.rb', line 9
def
swap(1, count)
el = @elements.pop
swim_down(1)
el
end
|
#sort ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/Heap/binary_heap/binary_heap_min.rb', line 16
def sort
el_temp = @elements.clone
result = []
result.push while count > 0
@elements = el_temp
result
end
|