Sha256: 0fcee5bc7aed4736e42160f919ab8103700ab9b80c5f185b7cb34ad29eb5f984

Contents?: true

Size: 685 Bytes

Versions: 2

Compression:

Stored size: 685 Bytes

Contents

require 'compsci/heap'
require 'compsci/timer'

include CompSci

puts <<EOF
#
# display the results of TernaryHeap push and pop
#

EOF

h = Heap.new(child_slots: 3)

puts "push: %s" % Array.new(30) { rand(99).tap { |i| h.push i } }.join(' ')
puts "array: #{h.array.inspect}"
puts "heap: #{h.heap?}"
puts h
puts
puts

puts "pop: %i" % h.pop
puts "array: #{h.array.inspect}"
puts "heap: #{h.heap?}"
puts h
puts
puts

puts "pop: %s" % Array.new(9) { h.pop }.join(' ')
puts "array: #{h.array.inspect}"
puts "heap: #{h.heap?}"
puts h
puts
puts

puts "push: %s" % Array.new(30) { rand(99).tap { |i| h.push i } }.join(' ')
puts "array: #{h.array.inspect}"
puts "heap: #{h.heap?}"
puts h
puts

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
compsci-0.3.0.1 examples/heap.rb
compsci-0.2.0.1 examples/heap.rb