Fléchette de recherche binaire
void binarySearch(value) {
int start = 0;
int end = list.length - 1;
int middle = ((start + end) / 2).floor();
while (list[middle] != value && start <= end) {
if (value < list[middle]) {
end = middle - 1;
} else {
start = middle + 1;
}
middle = ((start + end) / 2).floor();
}
if (list[middle] == value) {
print('The item $value is Exist and the middle is $middle');
} else {
print("Not exist");
}
}
}
Old-fashioned Okapi