Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created May 21, 2021 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/9ab2eba6de4b0d7d859b740bdffe5b36 to your computer and use it in GitHub Desktop.
Save cuongld2/9ab2eba6de4b0d7d859b740bdffe5b36 to your computer and use it in GitHub Desktop.
binary search using recursion in julia language
k=0
g=0
t=0
function binary_search(list,item,len_list)
global k
global g
global t
if list==[]
return 0
end
if t==1
return k
end
if last(list)==item
k= len_list - g
t=1
end
pop!(list)
g=g+1
return binary_search(list, item, len_list)
end
my_list = [1,3,5,6,8,10,12,21,34]
println(binary_search(my_list, 34, length(my_list)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment