Answers for "Binary search dart"

0

Binary search dart

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");
    }
  }
}
Posted by: Guest on January-23-2022

Code answers related to "Dart"

Browse Popular Code Answers by Language