public static void SortAlgos() { int[] A = new int[] { 3, 5, 6, 7, 2, 2, 4, 5, 19, 24, 6, 19, 43, 28 }; Console.WriteLine("\nInsertionSort"); SortAlgo sortAlgo = new SortAlgo(); foreach (var i in sortAlgo.InsertionSort(A)) { Console.Write("{0}\t", i); } Console.WriteLine("\nBubbleSort"); A = new int[] { 3, 5, 6, 7, 2, 2, 4, 5, 19, 24, 6, 19, 43, 28 }; foreach (var i in sortAlgo.BubleSort(A)) { Console.Write("{0}\t", i); } A = new int[] { 3, 5, 6, 7, 2, 2, 4, 5, 19, 24, 6, 19, 43, 28 }; sortAlgo.QuickSort(A, 0, A.Length - 1); Console.WriteLine("\nQuickSort"); foreach (var i in A) { Console.Write("{0}\t", i); } Console.WriteLine("\nMergeSort"); A = new int[] { 3, 5, 6, 7, 2, 2, 4, 5, 19, 24, 6, 19, 43, 28 }; sortAlgo.MergeSort(A, 0, A.Length - 1); foreach (var i in A) { Console.Write("{0}\t", i); } }
public void TestSortAlgos() { SortAlgo sortAlgo = new SortAlgo(); var bubbleSorted = sortAlgo.BubleSort(_arr); Assert.IsTrue(_sortedArr.ElementEquals(bubbleSorted)); var insertionSort = sortAlgo.InsertionSort(_arr); Assert.IsTrue(_sortedArr.ElementEquals(insertionSort)); var clone = new int[] { 3, 5, 6, 7, 2, 2, 19, 43, 28 }; sortAlgo.QuickSort(clone, 0, _arr.Length - 1); Assert.IsTrue(clone.ElementEquals(_sortedArr)); var quickSortClone = new int[] { 3, 5, 6, 7, 2, 2, 19, 43, 28 }; sortAlgo.MergeSort(quickSortClone, 0, quickSortClone.Length - 1); Assert.IsTrue(quickSortClone.ElementEquals(_sortedArr)); }