public static void SearchMethod() { var dataArray = DataGenerator.Generate(1000); QuickSort quickSort = new QuickSort(CompareMethodFactory.GetMethod(SortMode.SortByTwoKeys)); quickSort.Sort(dataArray); var data = dataArray[999]; Array.ForEach(dataArray, data => Console.WriteLine($"{data} - {data.GetHashCode()}")); int ind = SearchingAlgorithm.Search(dataArray, data); Console.WriteLine($"IndexAfterSearch:\t{ind}"); }
public static void Main(string[] args) { int[] arr = new int[] { 3, -1, 15, 4, 17, 2, 33, 0 }; Console.WriteLine("array = [{0}]", string.Join(", ", arr)); SortingAlgorithm.SelectionSort(arr); Console.WriteLine("sorted array = [{0}]", string.Join(", ", arr)); //SortingAlgorithm.SelectionSort(new int[0]); // Test sorting empty array //SortingAlgorithm.SelectionSort(new int[1]); // Test sorting single element array Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, -1000)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 0)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 17)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 10)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 1000)); }
static void Main() { int[] arr = { 15, 60, -1, 87, -305, 190, 0 }; Console.WriteLine("arr = [{0}]", string.Join(", ", arr)); SortingAlgorithm.SelectionSort(arr); Console.WriteLine("sorted = [{0}]", string.Join(", ", arr)); //SortingAlgorithm.SelectionSort((int[])null); //SortingAlgorithm.SelectionSort(new int[0]); SortingAlgorithm.SelectionSort(new int[1]); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, -1)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 0)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 10)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 190)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 500)); }
static void Main() { int[] arr = { 3, -1, 15, 4, 17, 2, 33, 0 }; Console.WriteLine("arr = [{0}]", string.Join(", ", arr)); SortingAlgorithm.SelectionSort(arr); Console.WriteLine("sorted = [{0}]", string.Join(", ", arr)); //SortingAlgorithm.SelectionSort((int[])null); // Test sorting non-existing array (null) //SortingAlgorithm.SelectionSort(new int[0]); // Test sorting empty array SortingAlgorithm.SelectionSort(new int[1]); // Test sorting single element array Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, -1000)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 0)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 17)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 10)); Console.WriteLine(SearchingAlgorithm.BinarySearch(arr, 1000)); }