Data-Structures/Sorting_Algorithms/Sorting_Algorithms/Program.cs
/// <summary>
/// Merge Sort divides the array recursively, sorts, then puts results into new array
/// </summary>
/// <param name="inputArray3"></param>
Merge Sort divides the array recursively, sorts, then puts results into new array
Merge Sort divides the array recursively sorts then puts results into new array
static void MergeSort(int[] inputArray3)
        {
            if(inputArray3.Length > 1)
            {
                int leftSize = inputArray3.Length / 2;
                int rightSize = inputArray3.Length - leftSize;
                int[] left = new int[leftSize];
                Array.Copy(inputArray3, 0, left, 0, leftSize);
                int[] right = new int[rightSize];
                Array.Copy(inputArray3, inputArray3.Length / 2, right, 0, rightSize);
                MergeSort(left);
                MergeSort(right);
                Merge(left, right, inputArray3);
            }
            Console.WriteLine(string.Join(",", inputArray3));
        }
static void MergeSort ( int [ ] inputArray3 ) { if ( inputArray3 . Length > 1 ) { int leftSize = inputArray3 . Length / 2 ; int rightSize = inputArray3 . Length - leftSize ; int [ ] left = new int [ leftSize ] ; Array . Copy ( inputArray3 , 0 , left , 0 , leftSize ) ; int [ ] right = new int [ rightSize ] ; Array . Copy ( inputArray3 , inputArray3 . Length / 2 , right , 0 , rightSize ) ; MergeSort ( left ) ; MergeSort ( right ) ; Merge ( left , right , inputArray3 ) ; } Console . WriteLine ( string . Join ( " " , inputArray3 ) ) ; }
Merge Sort divides the array recursively, sorts, then puts results into new array
Merge Sort divides the array recursively sorts then puts results into new array
//establish sizes of each half of the array //puts the first half of array in one empty array (left) //puts the second half the array in another empty array (right)
inputArray3
int[]
None