Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Binary-search/Icon/binary-search-1.icon
Normal file
11
Task/Binary-search/Icon/binary-search-1.icon
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
procedure binsearch(A, target)
|
||||
if *A = 0 then fail
|
||||
mid := *A/2 + 1
|
||||
if target > A[mid] then {
|
||||
return mid + binsearch(A[(mid+1):0], target)
|
||||
}
|
||||
else if target < A[mid] then {
|
||||
return binsearch(A[1+:(mid-1)], target)
|
||||
}
|
||||
return mid
|
||||
end
|
||||
13
Task/Binary-search/Icon/binary-search-2.icon
Normal file
13
Task/Binary-search/Icon/binary-search-2.icon
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
procedure main(args)
|
||||
target := integer(!args) | 3
|
||||
every put(A := [], 1 to 18 by 2)
|
||||
|
||||
outList("Searching", A)
|
||||
write(target," is ",("at "||binsearch(A, target)) | "not found")
|
||||
end
|
||||
|
||||
procedure outList(prefix, A)
|
||||
writes(prefix,": ")
|
||||
every writes(!A," ")
|
||||
write()
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue