public MainClass() { HeapSort heapSort = new HeapSort(); CombSort CombSort = new CombSort(); ArrayGenerator arrays = new ArrayGenerator(); int[] array1 = arrays.generateRandomArray(10); int[] array2 = arrays.generateRandomArray(100); //int[] array3 = arrays.generateRandomArray(1000); //int[] array4 = arrays.generateRandomArray(10000); // int[] array5 = arrays.generateRandomArray(100000); // int[] array6 = arrays.generateRandomArray(1000000); DateTime time1 = DateTime.Now; heapSort.sort(array1); DateTime time2 = DateTime.Now; TimeSpan total = new TimeSpan(time2.Ticks - time1.Ticks); Console.WriteLine(total.TotalMilliseconds + ""); DateTime time3 = DateTime.Now; heapSort.sort(array2); DateTime time4 = DateTime.Now; TimeSpan total1 = new TimeSpan(time3.Ticks - time4.Ticks); Console.WriteLine(total.TotalMilliseconds + ""); // sw.Write("Inverso MergeSort = " + total.TotalMilliseconds + "\n"); Console.ReadKey(true); }
public void test2() { int[] arraySize = { 100, 500, 1000, 5000, 10000, 50000, 100000 }; ArrayGenerator sort = new ArrayGenerator(); for (int i = 0; i < arraySize.Length; i++) { int[] testArray = sort.GenerateArray(arraySize[i], ArrayGenerator.Cases.Random); string s1 = arraySize[i].ToString(); string s2 = String.Concat(s1, ".txt"); string fileName = String.Concat(@"C:\Users\N56\Desktop\SortingAlgorithms\Best_", s2); string s3 = String.Concat("Количество элементов массива - ", s1); File.WriteAllText(fileName, s3 + Environment.NewLine, System.Text.Encoding.Default); for (int j = 0; j < 10; j++) { File.AppendAllText(fileName, "Начало нового теста\n" + Environment.NewLine); // Selection sort int[] test1 = testArray; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw = new System.Diagnostics.Stopwatch(); sw.Start(); ArraySort.SelectionSort(test1); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); File.AppendAllText(fileName, sw.Elapsed.TotalMilliseconds.ToString() + Environment.NewLine); // Insertion sort int[] test2 = testArray; sw = new System.Diagnostics.Stopwatch(); sw.Start(); ArraySort.InsertionSort(test2); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); File.AppendAllText(fileName, sw.Elapsed.TotalMilliseconds.ToString() + Environment.NewLine); // Shellsort int[] test3 = testArray; sw = new System.Diagnostics.Stopwatch(); sw.Start(); ArraySort.ShellSort(test3); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); File.AppendAllText(fileName, sw.Elapsed.TotalMilliseconds.ToString() + Environment.NewLine); // Quicksort int[] test4 = testArray; sw = new System.Diagnostics.Stopwatch(); sw.Start(); ArraySort.Quicksort(test4, 0, test4.Length - 1); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); File.AppendAllText(fileName, sw.Elapsed.TotalMilliseconds.ToString() + Environment.NewLine); // Merge sort int[] test5 = testArray; sw = new System.Diagnostics.Stopwatch(); sw.Start(); ArraySort.MergeSort(ref test5, 0, test5.Length - 1); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); File.AppendAllText(fileName, sw.Elapsed.TotalMilliseconds.ToString() + Environment.NewLine); // RadixSort int[] test6 = testArray; sw = new System.Diagnostics.Stopwatch(); sw.Start(); ArraySort.RadixSort(test6, 10, 10); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); File.AppendAllText(fileName, sw.Elapsed.TotalMilliseconds.ToString() + Environment.NewLine); File.AppendAllText(fileName, "------------------------" + Environment.NewLine); } } }