Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Binary-search/Seed7/binary-search-1.seed7
Normal file
20
Task/Binary-search/Seed7/binary-search-1.seed7
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
const func integer: binarySearchIterative (in array elemType: arr, in elemType: aKey) is func
|
||||
result
|
||||
var integer: result is 0;
|
||||
local
|
||||
var integer: low is 1;
|
||||
var integer: high is 0;
|
||||
var integer: middle is 0;
|
||||
begin
|
||||
high := length(arr);
|
||||
while result = 0 and low <= high do
|
||||
middle := low + (high - low) div 2;
|
||||
if aKey < arr[middle] then
|
||||
high := pred(middle);
|
||||
elsif aKey > arr[middle] then
|
||||
low := succ(middle);
|
||||
else
|
||||
result := middle;
|
||||
end if;
|
||||
end while;
|
||||
end func;
|
||||
16
Task/Binary-search/Seed7/binary-search-2.seed7
Normal file
16
Task/Binary-search/Seed7/binary-search-2.seed7
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
const func integer: binarySearch (in array elemType: arr, in elemType: aKey, in integer: low, in integer: high) is func
|
||||
result
|
||||
var integer: result is 0;
|
||||
begin
|
||||
if low <= high then
|
||||
result := (low + high) div 2;
|
||||
if aKey < arr[result] then
|
||||
result := binarySearch(arr, aKey, low, pred(result)); # search left
|
||||
elsif aKey > arr[result] then
|
||||
result := binarySearch(arr, aKey, succ(result), high); # search right
|
||||
end if;
|
||||
end if;
|
||||
end func;
|
||||
|
||||
const func integer: binarySearchRecursive (in array elemType: arr, in elemType: aKey) is
|
||||
return binarySearch(arr, aKey, 1, length(arr));
|
||||
Loading…
Add table
Add a link
Reference in a new issue