static void Main(string[] args) { int[] arr = { 10, 80, 30, 90, 40, 50, 70 }; BubbleSortAlgorithm bubbleSort = new BubbleSortAlgorithm(); InsertSortAlgorithm insertSort = new InsertSortAlgorithm(); ShellSortAlgorithm shellSort = new ShellSortAlgorithm(); HeapSortAlgorithm heapSort = new HeapSortAlgorithm(); SelectionSortAlgorithm selectSort = new SelectionSortAlgorithm(); MergeSortAlgorithm mergeSort = new MergeSortAlgorithm(); QuickSortAlgorithm quickSort = new QuickSortAlgorithm(); arr = quickSort.Sort(arr); for (int i = 0; i < arr.Length; i++) { Console.Write(arr[i]); Console.Write(' '); } Console.WriteLine(); Console.ReadLine(); }
public void QuickSortWithRandElementPartitionTest() { var rand = new Random(); var array = Enumerable.Range(0, 20).Select(x => rand.Next(-20, 21)).ToArray(); var algorithm = new QuickSortAlgorithm(new RandElementPartitionStrategy(rand)); AssertSort(array, algorithm); }
public void QuickSort_10NegativeNumbers_SortedArrayExpected() { int[] testArray = { -6, -37, -15, -49, -1, -111, -8, -6, -23, -4 }; int[] expectedArray = { -111, -49, -37, -23, -15, -8, -6, -6, -4, -1 }; int[] actualArray = QuickSortAlgorithm.QuickSort(testArray); CollectionAssert.AreEqual(expectedArray, actualArray); }
public void QuickSort_10PositiveAndNegativeNumbers_SortedArrayExpected() { int[] testArray = { -9, 15, 0, -89, 13, 8, -46, -7, 7, 12 }; int[] expectedArray = { -89, -46, -9, -7, 0, 7, 8, 12, 13, 15 }; int[] actualArray = QuickSortAlgorithm.QuickSort(testArray); CollectionAssert.AreEqual(expectedArray, actualArray); }
public void QuickSort_10PositiveNumbers_SortedArrayExpected() { int[] testArray = { 6, 15, 2, 9, 28, 63, 48, 6, 15, 3 }; int[] expectedArray = { 2, 3, 6, 6, 9, 15, 15, 28, 48, 63 }; int[] actualArray = QuickSortAlgorithm.QuickSort(testArray); CollectionAssert.AreEqual(expectedArray, actualArray); }
public void QuickSort_ValidItem() { var array = new List <int> { 10, 1, 4, 7, 3, 6, 12, 15 }; var sortedArray = new[] { 1, 3, 4, 6, 7, 10, 12, 15 }; var sortAlgorithm = new QuickSortAlgorithm(); var result = sortAlgorithm.QuickSort(array); Assert.NotNull(result); Assert.True(sortedArray.SequenceEqual(result)); }
public void QuickSort_SortedArray_SortedArrayExpected() { int[] testArray = new int[10]; int[] expectedArray = new int[10]; for (int i = 1; i < 11; i++) { testArray[i - 1] = i; expectedArray[i - 1] = i; } int[] actualArray = QuickSortAlgorithm.QuickSort(testArray); CollectionAssert.AreEqual(expectedArray, actualArray); }
private void Sort(int[] intTempArray, SortType sortType, CancellationToken cToken, HSBColor[] floatSortArray, bool hsb, int delay) { ISortingAlgorithm sortingAlgorithm = null; switch (sortType) { case SortType.QuickSort: sortingAlgorithm = new QuickSortAlgorithm(); break; case SortType.BubbleSort: sortingAlgorithm = new BubbleSortAlgorithm(); break; case SortType.HeapSort: sortingAlgorithm = new HeapSortAlgorithm(); break; case SortType.SelectionSort: sortingAlgorithm = new SelectionSortAlgorithm(); break; case SortType.MergeSort: sortingAlgorithm = new MergeSortAlgorithm(); break; break; case SortType.ParalellMergeSort: sortingAlgorithm = new ParalellMergeSortAlgorithm(); break; } sortingAlgorithm.Token = cToken; sortingAlgorithm.Delay = delay; if (hsb) { sortingAlgorithm.Sort(intTempArray, floatSortArray); } else { sortingAlgorithm.Sort(intTempArray); } }
public IActionResult Get() { var sortAlgorithm = new QuickSortAlgorithm(new RandElementPartitionStrategy(new System.Random())); var graph = new Graph(EdgeDirectionType.Undirected); graph.AddVertex(1); graph.AddVertex(2); graph.AddVertex(3); graph.AddVertex(4); graph.AddEdge(1, 2, 1, 1, EdgeDirectionType.Undirected); graph.AddEdge(2, 3, 2, 2, EdgeDirectionType.Undirected); graph.AddEdge(3, 4, 3, 5, EdgeDirectionType.Undirected); graph.AddEdge(4, 1, 4, 4, EdgeDirectionType.Undirected); graph.AddEdge(1, 3, 5, 3, EdgeDirectionType.Undirected); var algorithm = new PrimAlgorithm(); var edges = algorithm.GetMST(graph).ToList(); return(Ok(edges)); }
public void Setup() { _sut = new QuickSortAlgorithm(); }
private static int[] Sorting() { int[] arr = new int[] { 8, 3, 2, 7, 9, 1, 4, 1 }; Console.WriteLine("\n"); Console.WriteLine("Before HeapSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.ReadLine(); HeapSortAlgorithm.HeapSort(arr); Console.WriteLine("\n"); Console.WriteLine("After HeapSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.WriteLine("\n"); Console.ReadLine(); arr = new int[] { 4, 88, 23, 65, 2, 89, 7, 3, 1, 90, 4 }; Console.WriteLine("\n"); Console.WriteLine("Before MergeSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.ReadLine(); MergeSortAlgorithm.MergeSort(arr, 0, arr.Length - 1); Console.WriteLine("\n"); Console.WriteLine("After MergeSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.WriteLine("\n"); Console.ReadLine(); arr = new int[] { 8, 3, 2, 7, 9, 1, 4, 1 }; Console.WriteLine("\n"); Console.WriteLine("Before QuickSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.ReadLine(); QuickSortAlgorithm.QuickSort(arr, 0, arr.Length - 1); Console.WriteLine("\n"); Console.WriteLine("After QuickSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.WriteLine("\n"); Console.ReadLine(); return(arr); }
public void QuickSortAlgorithm_QuickSortTests(int[] array) { QuickSortAlgorithm.Sort(array); Assert.IsTrue(IsSorted(array)); }
public void QuickSort_NotInitializedArray_ArgumentNullExceptionExpected() { int[] testArray = null; int[] actualArray = QuickSortAlgorithm.QuickSort(testArray); }