Exemplo n.º 1
0
        public static void Start(int mode, bool debug)
        {
            Console.Write("Please enter amount of numbers: ");

            //Try parsing the entered value as an int. Outputs a boolean and if successful a numeric value.
            bool isNumeric = int.TryParse(Console.ReadLine(), out int length);

            //Restart if not numeric
            if (!isNumeric)
            {
                Console.WriteLine("Please enter a number");
                Start(mode, debug);
            }

            //Generate and fill an array with random numebrs using array randomizer in tools.
            int[] arr = Tools.Randomizers.RandomIntArrayFiller(length);

            //Choose sorting method according to the mode.
            if (mode == 1)
            {
                ArraySorter.HighToLow(arr, debug, mode);
            }
            else if (mode == 2)
            {
                ArraySorter.LowToHigh(arr, debug, mode);
            }
            else
            {
                //This code theoretically should never run, but it has to be here in case something goes wrong...
                Console.WriteLine("Unknown error (I'm too lazy to find out why)");
                Console.ReadKey();
                Environment.Exit(0);
            }
        }
Exemplo n.º 2
0
        public static void Start(int mode, bool debug)
        {
            Console.Write("Please enter total amount of numbers: ");

            //Try parsing the entered value as an int. Outputs a boolean and if successful a numeric value.
            bool isNumeric = int.TryParse(Console.ReadLine(), out int length);

            //Restart if not numeric
            if (!isNumeric)
            {
                Console.WriteLine("Please enter a number");
                Start(mode, debug);
            }

            Console.WriteLine("Enter array numeric values. Press enter per every number");
            int[] arr = new int[length];
            for (int i = 0; i < length; i++)
            {
                //Try parsing the entered value as an int. Outputs a boolean and if successful a numeric value.
                isNumeric = int.TryParse(Console.ReadLine(), out int num);
                if (isNumeric)
                {
                    arr[i] = num;
                }
                else
                {
                    Console.WriteLine("Value must be a number");
                    i--;
                }
            }

            //Choose sorting method according to the mode.
            if (mode == 1)
            {
                ArraySorter.HighToLow(arr, debug, mode);
            }
            else if (mode == 2)
            {
                ArraySorter.LowToHigh(arr, debug, mode);
            }
            else
            {
                //This code theoretically should never run, but it has to be here in case something goes wrong...
                Console.WriteLine("Unknown error (I'm too lazy to find out why)");
                Console.ReadKey();
                Environment.Exit(0);
            }
        }