/// <summary> /// Sorting the list using /// </summary> public void Sort(SortingAlgo algo = SortingAlgo.MergeSort) { // This allows multiple Sorting Agorithms if (algo == SortingAlgo.MergeSort) { MergeSort(ref this.Head); } }
public virtual void TestBasicSortingAlgo() { //AAA // Arrange int[] array = { 23, 4, 56, 1 }; int[] bubbleSortData = new int[array.Length]; int[] insertionSortData = new int[array.Length]; int[] mergeSortData = new int[array.Length]; int[] copyArray = new int[array.Length]; Array.Copy(array, copyArray, array.Length); Array.Copy(array, bubbleSortData, array.Length); Array.Copy(array, insertionSortData, array.Length); Array.Copy(array, mergeSortData, array.Length); //Act Array.Sort(copyArray); sort = new BubbleSort(); sort.Sort(bubbleSortData); sort = new InsertionSort(); sort.Sort(insertionSortData); sort = new MergeSort(); sort.Sort(mergeSortData); //Assert bool areEqual; areEqual = AreTwoArraysEqual(bubbleSortData, copyArray); Assert.AreEqual(true, areEqual); areEqual = AreTwoArraysEqual(insertionSortData, copyArray); Assert.AreEqual(true, areEqual); areEqual = AreTwoArraysEqual(mergeSortData, copyArray); Assert.AreEqual(true, areEqual); }
public void SelectionSortTest() { int[] unsorted = { 10, 8, 11, 6, 4, 13, 44, 21, 18, 23 }; //int[] unsorted = { 10, 8, 11, 6 }; SortingAlgo selSort = new SortingAlgo(); selSort.SelectionSort(unsorted); for (int index = 0; index <= unsorted.Length - 1; index++) { Console.Write(unsorted[index].ToString() + '\t'); } }
public virtual void TestSortAlgo_ParameterizedInput(int[] array) { int[] unsortedArray = array; sort = new BubbleSort(); sort.Sort(unsortedArray); int[] copy = array; Array.Sort(copy); bool isEqual = true; for (int i = 0; i < array.Length; i++) { if (unsortedArray[i] != copy[i]) { isEqual = false; break; } } Assert.AreEqual(true, isEqual); }
public void ArraysTest() { int[] visited = new int[5] { 1, 2, 3, 4, 5 }; Console.WriteLine(""); for (int i = 0; i < visited.Length; i++) { Console.WriteLine(visited[i]); } SortingAlgo test = new SortingAlgo(); test.ArrayUtil(ref visited); Console.WriteLine(""); for (int i = 0; i < visited.Length; i++) { Console.WriteLine(visited[i]); } }