Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Binary-search/Chapel/binary-search.chapel
Normal file
17
Task/Binary-search/Chapel/binary-search.chapel
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
proc binsearch(A:[], value) {
|
||||
var low = A.domain.dim(1).low;
|
||||
var high = A.domain.dim(1).high;
|
||||
while (low <= high) {
|
||||
var mid = (low + high) / 2;
|
||||
|
||||
if A(mid) > value then
|
||||
high = mid - 1;
|
||||
else if A(mid) < value then
|
||||
low = mid + 1;
|
||||
else
|
||||
return mid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
writeln(binsearch([3, 4, 6, 9, 11], 9));
|
||||
Loading…
Add table
Add a link
Reference in a new issue