-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
39 lines (30 loc) · 847 Bytes
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require_relative 'tree'
# arr = [4, 10, 12, 15, 18, 22, 24, 25, 31, 35, 44, 50, 66, 70, 90]
arr = Array.new(15) { rand(1..100) }
tree = Tree.new(arr.shuffle)
puts 'Tree:'
tree.pretty_print
puts "Balanced?: #{tree.balanced?}"
puts "Level order: #{tree.level_order}"
puts "Preorder: #{tree.preorder}"
puts "Postorder: #{tree.postorder}"
puts "Inorder: #{tree.inorder}"
puts
new_values = [123, 234, 345, 456]
new_values.each { |i| tree.insert(i) }
puts "Unbalancing with insertion of these values: #{new_values}"
puts
puts 'Tree:'
tree.pretty_print
puts "Balanced?: #{tree.balanced?}"
puts
tree.rebalance
puts 'Rebalancing...'
puts
puts 'Tree:'
tree.pretty_print
puts "Balanced?: #{tree.balanced?}"
puts "Level order: #{tree.level_order}"
puts "Preorder: #{tree.preorder}"
puts "Postorder: #{tree.postorder}"
puts "Inorder: #{tree.inorder}"