static void Main(string[] args)
        {
            Console.WriteLine("SORTING ALGORITHMS");
            int[] array = new int[10] {
                100, 50, 20, 40, 10, 60, 80, 70, 90, 30
            };
            DateTime start;

            Console.WriteLine("The real array: [{0}]\n", string.Join(", ", array));

            //bubble
            int[] test1 = new int[array.Length];
            Array.Copy(array, test1, array.Length);
            start = DateTime.Now;
            Console.WriteLine("\tBubble sort: [{0}] in {1}s", string.Join(", ", Bubble.Sort(test1)), (DateTime.Now - start).TotalSeconds);

            //selection
            int[] test2 = new int[array.Length];
            Array.Copy(array, test2, array.Length);
            start = DateTime.Now;
            Console.WriteLine("\tSelection sort: [{0}] in {1}s", string.Join(", ", Selection.Sort(test2)), (DateTime.Now - start).TotalSeconds);

            //insetrtion
            int[] test3 = new int[array.Length];
            Array.Copy(array, test3, array.Length);
            start = DateTime.Now;
            Console.WriteLine("\tInsertion sort: [{0}] in {1}s", string.Join(", ", Insertion.Sort(test3)), (DateTime.Now - start).TotalSeconds);

            //merge
            int[] test4 = new int[array.Length];
            Array.Copy(array, test4, array.Length);
            start = DateTime.Now;
            Console.WriteLine("\tMerge sort: [{0}] in {1}s", string.Join(", ", Merge.Sort(test4)), (DateTime.Now - start).TotalSeconds);

            //quick
            int[] test5 = new int[array.Length];
            Array.Copy(array, test5, array.Length);
            start = DateTime.Now;
            Console.WriteLine("\tQuick sort: [{0}] in {1}s", string.Join(", ", Quick.Sort(test5)), (DateTime.Now - start).TotalSeconds);

            Console.WriteLine("\nThe real array: [{0}]", string.Join(", ", array));
        }
Beispiel #2
0
        private static void Main()
        {
            var selection = 0;

            while (selection != -1)
            {
                var arr = new List <int>(new[]
                {
                    4, 5, 2, 1, 3, 7, 6, 22, 23, 25, 27, 29, 8, 9, 10, 32, 31, 43, 54, 43, 42, 12, 34, 38, 37, 36, 19,
                    18, 11, 55, 57, 56, 59, 13
                });
                Console.Clear();
                Console.WriteLine("0. Unsorted\n1. Bubble\n2. Insertion\n3. Selection\n4. Heap\n5. Radix\n6. Quick\n7. Shell\n8. Merge\n9. Tim\n10. Cocktail");
                Console.Write("Your Choice : ");
                selection = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());
                var s = "";
                switch (selection)
                {
                case 0:
                    s = "Unsorted";
                    break;

                case 1:
                    arr = Bubble <int> .Sort(arr);

                    s = "Bubble";
                    break;

                case 2:
                    arr = Insertion <int> .Sort(arr);

                    s = "Insertion";
                    break;

                case 3:
                    arr = Selection <int> .Sort(arr);

                    s = "Selection";
                    break;

                case 4:
                    arr = Heap <int> .Sort(arr);

                    s = "Heap";
                    break;

                case 5:
                    arr = Radix.Sort(arr);
                    s   = "Radix";
                    break;

                case 6:
                    arr = Quick <int> .Sort(arr);

                    s = "Quick";
                    break;

                case 7:
                    arr = Shell <int> .Sort(arr);

                    s = "Shell";
                    break;

                case 8:
                    arr = Merge <int> .Sort(arr);

                    s = "Merge";
                    break;

                case 9:
                    arr = Tim <int> .Sort(arr);

                    s = "Tim";
                    break;

                case 10:
                    arr = Cocktail <int> .Sort(arr);

                    s = "Cocktail";
                    break;

                default:
                    Console.WriteLine("Choice Wrong");
                    break;
                }

                Console.Clear();
                Console.WriteLine(s + " Sort");
                foreach (var i in arr)
                {
                    Console.Write(i + " ");
                }
                Console.ReadKey();
            }
        }