I'm using the following c# binary search algorithm to search for doubles in a double array containing 256 - 4096 elements:
- public static void Search(double[] array, double key)
- {
- Quicksort.Sort(array);
- int min = 0;
- int max = array.Length - 1;
- bool found = false;
- while (min <= max)
- {
- int mid = (min + max) / 2;
- if (array[mid] == key)
- {
- found = true;
- Console.WriteLine($"{key} was found at index {mid} of the array");
- }
- else if (array[mid] > key)
- max = mid - 1;
- else if (array[mid] < key)
- min = mid + 1;
- }
- if (found == false)
- Console.WriteLine($"{key} wasn't found in the array.");
Thanks for the help!
Manoj BhoirPosted Apr 29, 2019, 1:32 AM
Amit KumarPosted Apr 28, 2019, 11:27 PM