Exemplo n.º 1
0
        public static void CallQuickSort(int[] arr)
        {
            int[] newArr = NewArr(arr);
            Console.WriteLine("Quick sort");
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            long memory = GC.GetTotalMemory(false);

            {
                Quick_Sort.QuickSort(newArr, 0, newArr.Length - 1);
            }
            stopwatch.Stop();
            Print(newArr);
            Console.WriteLine("Running time: {0}", stopwatch.Elapsed);
            Console.WriteLine("Memory usage: {0}", memory);
            Console.WriteLine();
        }
Exemplo n.º 2
0
        public static int MinTime(int[] arr)
        {
            int min = 0;

            int[] newArr = new int[arr.Length];
            newArr = NewArr(arr);
            Stopwatch[] timearr    = new Stopwatch[5];
            Stopwatch   stopwatch1 = new Stopwatch();
            Stopwatch   stopwatch2 = new Stopwatch();
            Stopwatch   stopwatch3 = new Stopwatch();
            Stopwatch   stopwatch4 = new Stopwatch();
            Stopwatch   stopwatch5 = new Stopwatch();

            stopwatch1.Start();
            Insertion_Sort.InsertionSort(newArr);
            stopwatch1.Stop();
            timearr[0] = stopwatch1;
            newArr     = NewArr(arr);


            stopwatch2.Start();
            Bubble_sort.BubbleSort(newArr);
            stopwatch2.Stop();
            timearr[1] = stopwatch2;
            newArr     = NewArr(arr);


            stopwatch3.Start();
            Merge_Sort.MergeSort(newArr, 0, newArr.Length - 1);
            stopwatch3.Stop();
            timearr[2] = stopwatch3;
            newArr     = NewArr(arr);


            stopwatch4.Start();
            Heap_Sort.heapSort(arr);
            stopwatch4.Stop();
            timearr[3] = stopwatch4;
            newArr     = NewArr(arr);


            stopwatch5.Start();
            Quick_Sort.QuickSort(newArr, 0, newArr.Length - 1);
            stopwatch5.Stop();
            timearr[4] = stopwatch5;
            newArr     = NewArr(arr);


            Stopwatch minStopWatch = Min(timearr);

            if (minStopWatch.Elapsed == stopwatch1.Elapsed)
            {
                min = 1;
            }
            else if (minStopWatch.Elapsed == stopwatch2.Elapsed)
            {
                min = 2;
            }
            else if (minStopWatch.Elapsed == stopwatch3.Elapsed)
            {
                min = 3;
            }
            else if (minStopWatch.Elapsed == stopwatch4.Elapsed)
            {
                min = 4;
            }
            else
            {
                min = 5;
            }

            return(min);
        }