Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MergeSort
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int[] arrayStart = new int[] { 5, 4, 1, 8, 7, 2, 6, 3};
- Console.WriteLine(someReturn(arrayStart));
- }
- static int[] Function (int[] someArray)
- {
- int size = someArray.Length;
- int[] outputArray = new int[size];
- int[] firstArray = new int[size / 2];
- for (int i = 0; i < size / 2; i++)
- {
- firstArray[i] = someArray[i];
- }
- int[] secondArray = new int[size / 2];
- for (int i = size / 2; i < size; i++)
- {
- secondArray[i] = someArray[i];
- }
- int k = 1;
- int j = 1;
- for (int i = 0; i < size; i++)
- {
- if (firstArray[k] < secondArray[j])
- {
- outputArray[i] = firstArray[k];
- k++;
- }
- else
- {
- outputArray[i] = secondArray[j];
- j++;
- }
- }
- return outputArray;
- }
- static int[] someReturn(int[] arrayForReturn)
- {
- int size = arrayForReturn.Length;
- int[] firstArray = new int[size / 2];
- int[] secondArray = new int[size / 2];
- if (arrayForReturn.Length == 2)
- {
- firstArray[0] = arrayForReturn[0];
- secondArray[0] = arrayForReturn[1];
- }
- else
- {
- for (int i = 0; i < size / 2; i++)
- {
- firstArray[i] = arrayForReturn[i];
- }
- for (int i = size / 2; i < size; i++)
- {
- secondArray[i] = arrayForReturn[i];
- }
- firstArray = someReturn(firstArray);
- secondArray = someReturn(secondArray);
- }
- int k = 1;
- int j = 1;
- size = firstArray.Length + secondArray.Length;
- int[] outputArray = new int[size];
- for (int i = 0; i < size; i++)
- {
- if (firstArray[k] < secondArray[j])
- {
- outputArray[i] = firstArray[k];
- k++;
- }
- else
- {
- outputArray[i] = secondArray[j];
- j++;
- }
- }
- return outputArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment