public static void Main(string[] args) { int[] array = new int[10] { 3, 6, 1, 8, 2, 5, 9, 2, 7, 4 }; //Bubble Sort SortArray <int> .BubbleSort(array); Console.Write("Result of Bubble Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); //Insertion Sort SortArray <int> .InsertionSort(array); Console.Write("Result of Insertion Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); //Selection Sort SortArray <int> .SelectionSort(array); Console.Write("Result of Selection Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); //Merge Sort SortArray <int> .MergeSort(array); Console.Write("Result of Merge Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } }
public void TestBinarySearch() { var random = new Random(); for (int t = 0; t < 100000; t++) { var array = CommonArrayFunctions.InitIntArray(random.Next(50, 150), 0, random.Next(50, 150)); var sortedArray = new int[array.Length]; array.CopyTo(sortedArray, 0); SortArray.SelectionSort(sortedArray); for (int t2 = 0; t2 < array.Length; t2++) { var result = SearchInArray.BinarySearchRecursive(sortedArray, 0, array.Length, array[t2]); Assert.IsTrue(array[t2] == sortedArray[result]); } } }