public static void SearchInArray() { BinarySearch binarySearch = new BinarySearch(); Console.Write("Array: "); DataStructure.ArrayOperations array = new DataStructure.ArrayOperations(binarySearch.n); array.Print(binarySearch.a); int index = binarySearch.SearchInArray_IterativeMethod(); Console.WriteLine("Search element {0} found at index {1}", binarySearch.key, index); Console.WriteLine("No of iterations: {0}", binarySearch.noOfIteration); index = binarySearch.SearchInArray_RecursiveMethod(binarySearch.low, binarySearch.high, binarySearch.key); Console.WriteLine("Search element {0} found at index {1}", binarySearch.key, index); Console.WriteLine("No of recursion: {0}", binarySearch.noOfRecursion); }
public int SearchInArray(SearchMethod searchMethod = SearchMethod.Iterative) { int keyIndex; if (showMessages) { Console.Write("Array: "); } DataStructure.ArrayOperations array = new DataStructure.ArrayOperations(n); if (showMessages) { array.Print(this.a); } if (searchMethod == SearchMethod.Iterative) { keyIndex = SearchInArray_IterativeMethod(); if (showMessages) { Console.WriteLine("Search element {0} found at index {1}", key, keyIndex); } if (showMessages) { Console.WriteLine("No of iterations: {0}", noOfIteration); } } else { keyIndex = SearchInArray_RecursiveMethod(low, high, key); if (showMessages) { Console.WriteLine("Search element {0} found at index {1}", key, keyIndex); } if (showMessages) { Console.WriteLine("No of recursion: {0}", noOfRecursion); } } return(keyIndex); }