mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
Minor code style improvements
Tabs are corrected, semantic blocks are separated.
This commit is contained in:
parent
4fa7e1a672
commit
e6b674275e
1 changed files with 7 additions and 4 deletions
|
@ -8,18 +8,21 @@ def binary_search(array, key)
|
|||
return middle if array[middle] == key
|
||||
|
||||
if key < array[middle]
|
||||
back = middle - 1
|
||||
else
|
||||
front = middle + 1
|
||||
end
|
||||
back = middle - 1
|
||||
else
|
||||
front = middle + 1
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
puts "Enter a sorted space-separated list:"
|
||||
arr = gets.chomp.split(' ').map(&:to_i)
|
||||
|
||||
puts "Enter the value to be searched:"
|
||||
value = gets.chomp.to_i
|
||||
|
||||
puts if binary_search(arr, value) != nil
|
||||
"Found at index #{binary_search(arr, value)}"
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue