public void QuickSortTest1() { List <int> list = new List <int>() { 2, 20, 1, 15, 3, 11, 13, 6, 16, 10, 19, 5, 4, 9, 8, 14, 18, 17, 7, 12 }; QuickSortAlgoritm q = new QuickSortAlgoritm(); q.AddOneHandler += Q_AddOneHandler; q.QuickSort(list, 0, list.Count - 1); Assert.Fail(); }
public void ChoosePivotTest() { //arrange List <int> list = new List <int>() { 3, 8, 2, 5, 1, 4, 7, 6, 12, 10, 9, 11 }; //act QuickSortAlgoritm q = new QuickSortAlgoritm(); int j = q.ChoosePivot(list, 1, 2).Key; //assert Assert.AreEqual(j, 2); }
public void QuickSortTest() { //arrange List <int> list = new List <int>() { 3, 8, 2, 5, 1, 4, 7, 6, 12, 10, 9, 11 }; List <int> list1 = new List <int>(list); //act QuickSortAlgoritm q = new QuickSortAlgoritm(); q.QuickSort(list, 0, list.Count - 1); //assert Assert.AreEqual(list1, list); }
public void PartitionTest() { //arrange List <int> list = new List <int>() { 3, 8, 2, 5, 1, 4, 7, 6 }; //act QuickSortAlgoritm q = new QuickSortAlgoritm(); list.ForEach((x) => Console.Write(x + " ")); Console.WriteLine(); int j = q.Partition(list, 0, list.Count); list.ForEach((x) => Console.Write(x + " ")); Console.WriteLine(); Console.WriteLine(j); //assert Assert.Fail(); }
static void Main(string[] args) { int temp = 0; string path = @"C:\Users\HP\source\repos\laba10_!\sorted.dat"; int[] array = new int[100]; Random rand = new Random(); for (int i = 0; i < array.Length; i++) { array[i] = rand.Next(0, 30); } for (int i = 0; i < array.Length - 1; i++) { for (int j = i + 1; j < array.Length; j++) { if (array[i] > array[j]) { temp = array[i]; array[i] = array[j]; array[j] = temp; } } } int[] array_ascending = array; int[] array_descending = new int[array.Length]; for (int i = array.Length - 1; i > -1; i--) { array_descending[i] = array_ascending[i]; } int cnt = 0; int swap = 0; TimeSpan time = new TimeSpan(); QuickSortAlgoritm quickSort = new QuickSortAlgoritm(); MergeSortAlgoritm mergeSort = new MergeSortAlgoritm(); HeapSortAlgoritm heapSort = new HeapSortAlgoritm(); Console.WriteLine("QuickSort"); var arr = quickSort.QuickSort((int[])randomValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив сгенерированный случайным образом\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); Console.WriteLine("QuickSort"); arr = quickSort.QuickSort((int[])descendingValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив по убыванию\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); Console.WriteLine("QuickSort"); arr = quickSort.QuickSort((int[])ascendingValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив по возростанию\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); Console.WriteLine("\n\n"); Console.WriteLine("MergeSort"); mergeSort.MergeSort((int[])randomValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив сгенерированный случайным образом\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); mergeSort.MergeSort((int[])descendingValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив сгенерированный по убыванию\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); mergeSort.MergeSort((int[])ascendingValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив по возростанию\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); Console.WriteLine("\n\n"); Console.WriteLine("HeapSort"); heapSort.HeapSort((int[])randomValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив сгенерированный случайным образом\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); heapSort.HeapSort((int[])descendingValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив по убыванию\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); heapSort.HeapSort((int[])ascendingValue.Clone(), ref cnt, ref swap, ref time); Console.Write($"Массив по возростанию\nЗатраченное время на сортировку - {time} \nколичество сравнений - {cnt} \nколичество перестановок - {swap}\n"); writeInFile(arr); }