Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MySort mySort = new MySort();

            int[]  testArray = new int[ARRAY_LEN];
            Random rd        = new Random();

            for (int i = 0; i < ARRAY_LEN; i++)
            {
                testArray[i] = rd.Next(0, ARRAY_LEN);
            }

            //mySort.MergeSort (testArray);

            Console.WriteLine(mySort.IsSorted(testArray));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            MySort mySort = new MySort();

            int[]  testArray = new int[ARRAY_LEN];
            Random rd        = new Random();

            for (int i = 0; i < ARRAY_LEN; i++)
            {
                testArray[i] = rd.Next(0, ARRAY_LEN);
            }

            int[] tempArray = new int[ARRAY_LEN];

            //InsertSort
            testArray.CopyTo(tempArray, 0);
            DateTime beginTime = System.DateTime.Now;

            mySort.InsertSort(tempArray);
            DateTime endTime = System.DateTime.Now;
            TimeSpan ts      = endTime.Subtract(beginTime);

            Console.WriteLine("InsertSort:");
            Console.WriteLine(ts.Milliseconds);
            Console.WriteLine(mySort.IsSorted(tempArray));

            //BubbleSort
            testArray.CopyTo(tempArray, 0);
            beginTime = System.DateTime.Now;
            mySort.BubbleSort(tempArray);
            endTime = System.DateTime.Now;
            ts      = endTime.Subtract(beginTime);
            Console.WriteLine("BubbleSort:");
            Console.WriteLine(ts.Milliseconds);
            Console.WriteLine(mySort.IsSorted(tempArray));

            //SelectionSort
            testArray.CopyTo(tempArray, 0);
            beginTime = System.DateTime.Now;
            mySort.SelectionSort(tempArray);
            endTime = System.DateTime.Now;
            ts      = endTime.Subtract(beginTime);
            Console.WriteLine("SelectionSort:");
            Console.WriteLine(ts.Milliseconds);
            Console.WriteLine(mySort.IsSorted(tempArray));

            //QuickSort
            testArray.CopyTo(tempArray, 0);
            beginTime = System.DateTime.Now;
            mySort.QuickSort(tempArray);
            endTime = System.DateTime.Now;
            ts      = endTime.Subtract(beginTime);
            Console.WriteLine("QuickSort:");
            Console.WriteLine(ts.Milliseconds);
            Console.WriteLine(mySort.IsSorted(tempArray));

            //MergeSort
            testArray.CopyTo(tempArray, 0);
            beginTime = System.DateTime.Now;
            mySort.MergeSort(tempArray);
            endTime = System.DateTime.Now;
            ts      = endTime.Subtract(beginTime);
            Console.WriteLine("MergeSort:");
            Console.WriteLine(ts.Milliseconds);
            Console.WriteLine(mySort.IsSorted(tempArray));



            //Console.WriteLine( mySort.IsSorted(testArray));
        }