Method: AVLTree#rebalance

Defined in:
lib/nswtopo/avl_tree.rb

#rebalanceObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nswtopo/avl_tree.rb', line 63

def rebalance
  update_height
  case balance
  when +2
    @left.rotate_left if @left.balance == -1
    rotate_right
  when -2
    @right.rotate_right if @right.balance == 1
    rotate_left
  end unless empty?
end