Method: Heap#initialize

Defined in:
lib/mega/heap.rb

#initialize(array) ⇒ Heap

Initialise the heap. If supplied an array, build the heap with the values of the array. The array can be unsorted. Note: this method can only be called by superclasses



92
93
94
95
# File 'lib/mega/heap.rb', line 92

def initialize(array)
  @array, @heap_size = array, array.length
  (@heap_size/2 - 1).downto(0) { |i| heapify(i) }
end