You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 lines
275 B
Ruby

def create_binary_tree(arr, arr_start, arr_end)
return if arr_start > arr_end
mid = arr_start + arr_end / 2
root = Node.new(arr[mid])
root.left = create_binary_tree(arr, arr_start, mid - 1)
root.right = create_binary_tree(arr, mid + 1, arr_end)
root
end