예제 #1
0
        private static void TestSortersAllPermutations(SortableCollection <int> collection)
        {
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();
            Console.WriteLine("Calculating time (Permutation without repetitions) ...");

            var copy = collection.GetCopy();

            stopWatch.Reset();
            sorter = new SelectionSorter <int>();
            Console.WriteLine("========================SelectionSorter result=================================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("SelectionSorter:    " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new UpgradedSelectionSorter <int>();
            Console.WriteLine("========================UpgradedSelectionSorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("UpgradedSelection  :" + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new QuickSorter <int>();
            Console.WriteLine("========================Quicksorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("Quicksorter:        " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new MergeSorter <int>();
            Console.WriteLine("========================MergeSorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("MergeSorter:        " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new MergeInsertionSorter <int>();
            Console.WriteLine("========================MergeInsertSorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("MergeInsertSorter:  " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new InsertionSorter <int>();
            Console.WriteLine("========================Insertion result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("Insertion:          " + stopWatch.Elapsed);
            Console.WriteLine();
        }
        internal static void Main()
        {
            var collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 0, 101 });

            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter <int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("Quicksorter result:");
            collection.Sort(new Quicksorter <int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection <int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            collection.Sort(new MergeSorter <int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101));
            Console.WriteLine();

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101));
            Console.WriteLine();

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
        }
예제 #3
0
 private static void TestShuffle(SortableCollection <int> collection, int shuffles)
 {
     Console.Write("\nOriginal collection: ");
     collection.PrintAllItemsOnConsole();
     for (int i = 0; i < shuffles; i++)
     {
         var copy = collection.GetCopy();
         Console.WriteLine("\nShuffle...");
         copy.Shuffle();
         copy.PrintAllItemsOnConsole();
     }
 }