T
T
Timofey2020-10-14 01:34:08
.NET
Timofey, 2020-10-14 01:34:08

Why is an array needed in the method and what should be done so that when entering data into the array, an exception is not thrown?

using System;



namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            
            

            void Func(int[] numbers,int L, int R)
            {
                int  middle, I, J, F, Z;
                
                I = L; J = R;
                middle = (L + R) / 2;
                do
                {
                    do
                    {
                        F = 0;
                        if (numbers[I] < numbers[middle]) F = -1;
                        if (numbers[I] > numbers[middle]) F = 1;
                        if (F > 0) I = I + 1;
                        Console.WriteLine(I);

                    }
                    while
                    (F < 0);
                    do
                    {
                        F = 0;
                        if (numbers[J] < numbers[middle]) F = -1;
                        if (numbers[J] > numbers[middle]) F = 1;
                        if (F > 0) J = J + 1;
                        Console.WriteLine(J);
                    }
                    while
                    (F < 0);
                    if  (I <= J)
                    { 
                        Z = numbers[I]; numbers[I] = numbers[J]; numbers[J] = Z;
                    }
                }
                while
                (I <= J);
                if (L < J) Func(numbers, L, J);
                 else if (I < R) Func(numbers, I, R);
            }
            Func(numbers,15, 10);
        }
    }
}


Why do we need an array in this method, what role does it play and how to bypass the exception so as not to process it, a stupid question, but the code was written from an algorithmic language and I'm sure there is no such thing in terms of error handling

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cicatrix, 2020-10-14
@timofeygusevopal

You saved the code crookedly, apparently. You have func nested in main. This is firstly, and secondly, why - this is after all quick sorting, and yes, in order to sort an array, you need to pass it to it. And inputting data to an array in your code is not currently present.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question