Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
16
Task/Binary-search/Phix/binary-search-1.phix
Normal file
16
Task/Binary-search/Phix/binary-search-1.phix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function binary_search(sequence s, object val, integer low, integer high)
|
||||
integer mid, cmp
|
||||
if high < low then
|
||||
return 0 -- not found
|
||||
else
|
||||
mid = floor( (low + high) / 2 )
|
||||
cmp = compare(s[mid], val)
|
||||
if cmp > 0 then
|
||||
return binary_search(s, val, low, mid-1)
|
||||
elsif cmp < 0 then
|
||||
return binary_search(s, val, mid+1, high)
|
||||
else
|
||||
return mid
|
||||
end if
|
||||
end if
|
||||
end function
|
||||
17
Task/Binary-search/Phix/binary-search-2.phix
Normal file
17
Task/Binary-search/Phix/binary-search-2.phix
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function binary_search(sequence s, object val)
|
||||
integer low, high, mid, cmp
|
||||
low = 1
|
||||
high = length(s)
|
||||
while low <= high do
|
||||
mid = floor( (low + high) / 2 )
|
||||
cmp = compare(s[mid], val)
|
||||
if cmp > 0 then
|
||||
high = mid - 1
|
||||
elsif cmp < 0 then
|
||||
low = mid + 1
|
||||
else
|
||||
return mid
|
||||
end if
|
||||
end while
|
||||
return 0 -- not found
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue