Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter length of array to be randomly generated:");
            int n = Convert.ToInt32(Console.ReadLine());

            int[]  Unsorted = new int[n];
            Random rnd      = new Random();

            for (int i = 0; i < n; i++)
            {
                Unsorted[i] = rnd.Next(1000);
            }
            PrintArray(Unsorted);
            Console.WriteLine("Which sorting algorithm would you like?");
            Console.WriteLine("1 - BubbleSort");
            Console.WriteLine("2 - InsertionSort");
            Console.WriteLine("3 - SelectionSort");
            Console.WriteLine("4 - MergeSort");
            Console.WriteLine("5 - QuickSort");
            Console.WriteLine("6 - ShellSort");
            int choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
            case 1:
                PrintArray(Bubble.Sort(Unsorted));
                break;

            case 2:
                PrintArray(Insertion.Sort(Unsorted));
                break;

            case 3:
                PrintArray(Selection.Sort(Unsorted));
                break;

            case 4:
                List <int> UnsortedList = new List <int>();
                UnsortedList = Unsorted.ToList <int>();
                PrintList(Merge.Sort(UnsortedList));
                break;

            case 5:
                PrintArray(Quick.Sort(Unsorted));
                break;

            case 6:
                PrintArray(Shell.Sort(Unsorted));
                break;

            default:
                throw new ArgumentException("Invalid input");
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            int[] arr = { 7, 8, 4, 6, 2, 1 };

            Console.WriteLine("Select sorting algorithm:");
            Console.WriteLine("1. Bubble Sort");
            Console.WriteLine("2. Insertion Sort");
            string selection = Console.ReadLine();

            if (selection == "1")
            {
                Bubble.sort(arr);
            }
            else
            {
                Insertion.sort(arr);
            }
        }