Esempio n. 1
0
        public static void Main()
        {
            Console.WriteLine("Hello World!\n");

            int[] qList = new[] { 9, 7, 2, 6, 1 };
            Console.WriteLine("List before quick sort: [{0}]", string.Join(", ", qList));
            QuickSort qSorter = new QuickSort();
            qSorter.sort(qList, 0, qList.Length);
            SortAsserter(qList);
            Console.WriteLine("List after quick sort: [{0}]\n", string.Join(", ", qList));

            int[] sList = new[] { 2, 6, 3, 1, 9 };
            Console.WriteLine("List before selection sort: [{0}]", string.Join(", ", sList));
            SelectionSort sSorter = new SelectionSort();
            sSorter.sort(sList, 0, 0);
            SortAsserter(sList);
            Console.WriteLine("List after selection sort: [{0}]\n", string.Join(", ", sList));

            int[] iList = new[] { 2, 8, 5, 7, 3 };
            Console.WriteLine("List before insertion sort: [{0}]", string.Join(", ", iList));
            InsertionSort iSorter = new InsertionSort();
            iSorter.sort(iList, 0, 0);
            SortAsserter(iList);
            Console.WriteLine("List after insertion sort: [{0}]\n", string.Join(", ", iList));

            int[] bList = new[] { 1, 7, 3, 2, 0 };
            Console.WriteLine("List before bubble sort: [{0}]", string.Join(", ", bList));
            BubbleSort bSorter = new BubbleSort();
            bSorter.sort(bList, 0, 0);
            SortAsserter(bList);
            Console.WriteLine("List after bubble sort: [{0}]\n", string.Join(", ", bList));

            int[] mList = new[] { 6, 8, 3, 0, 1 };
            Console.WriteLine("List before merge sort: [{0}]", string.Join(", ", mList));
            MergeSort mSorter = new MergeSort();
            mSorter.sort(mList, 0, mList.Length - 1);
            SortAsserter(mList);
            Console.WriteLine("List after merge sort: [{0}]\n", string.Join(", ", mList));

            MyList<int> myList = new MyList<int>(1);
            TestList(myList);

            Console.WriteLine("Testing running times:\n");

            RunningTimes.SortPlot(qSorter, 70000, "Quick Sort");
            RunningTimes.SortPlot(sSorter, 70000, "Selection Sort");
            RunningTimes.SortPlot(iSorter, 70000, "Insertion Sort");
            RunningTimes.SortPlot(bSorter, 70000, "Bubble Sort");
            RunningTimes.SortPlot(mSorter, 70000, "Merge Sort");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Database db     = new Database();
            var      shirts = db.Shirts.ToArray();

            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("BubbleSort");
            Console.WriteLine("~~~~~~~~~~~");

            Console.WriteLine("Ascending order by size, color and fabric");
            BubbleSort.SizeColorFabricAscendingOrder(shirts);
            PrintAllItems(shirts);

            Console.WriteLine("Descending order by size, color and fabric");
            BubbleSort.SizeColorFabricDescendingOrder(shirts);
            PrintAllItems(shirts);

            Console.WriteLine("Ascending order by fabric");
            BubbleSort.FabricAscendingOrder(shirts);
            PrintAllItems(shirts);

            Console.WriteLine("Descending order by fabric");
            BubbleSort.FabricDescendingOrder(shirts);
            PrintAllItems(shirts);

            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("QuickSort");
            Console.WriteLine("~~~~~~~~~~~");

            Console.WriteLine("Ascending order by color");
            QuickSort.ColorAscending(shirts);
            PrintAllItems(shirts);

            Console.WriteLine("Descending order by color");
            QuickSort.ColorDescending(shirts);
            PrintAllItems(shirts);

            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("BucketSort");
            Console.WriteLine("~~~~~~~~~~~");

            Console.WriteLine("Ascending order by size");
            var listSizeAsc = BucketSort.SizeAscending(shirts);

            PrintAllItems(listSizeAsc.ToArray());

            Console.WriteLine("Descending order by size");
            var listSizeDesc = BucketSort.SizeDescending(shirts);

            PrintAllItems(listSizeDesc.ToArray());



            UserApplication.BuyShirt();

            Console.ReadKey();
        }