Пример #1
0
        static void Main(string[] args)
        {
            int[] Arr = new int[] { 1, 100, 45, 62, 3, 2, 1000 };

            //Merge Sort
            Merge_Sort mergeobj = new Merge_Sort();

            mergeobj.MergeSort(Arr);
            Console.WriteLine("Sorting using Merge Sort Method");
            mergeobj.Print(Arr);

            //Counting Sort
            Console.WriteLine("Sorting using Counting Sort Method");
            CountingSort obj = new CountingSort();

            obj.Counting_Sort(Arr, 10001);

            //Heap Sort
            Console.WriteLine("Sorting using Heap Sort Method");
            HeapSort heap = new HeapSort();

            heap.Heap_Sort(Arr);

            Console.ReadKey();
        }
Пример #2
0
        public static void CallMergeSort(int[] arr)
        {
            int[] newArr = NewArr(arr);
            Console.WriteLine("Merge sort");
            Stopwatch stopwatch = new Stopwatch();

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

            {
                Merge_Sort.MergeSort(newArr, 0, newArr.Length - 1);
            }
            stopwatch.Stop();
            Print(newArr);
            Console.WriteLine("Running time: {0}", stopwatch.Elapsed);
            Console.WriteLine("Memory usage: {0}", memory);
            Console.WriteLine();
        }
Пример #3
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);
        }