using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication14 { class Program { static void Main(string[] args) { var array = new int[5]; for (int i = 0; i < 5; i++) array[i] = int.Parse(Console.ReadLine()); array = MergeSort(array); foreach (int i in array) Console.WriteLine(i); Console.ReadKey(); } static int[] MergeSort(int[] a) { if (a.Length > 1) { var L = new int[a.Length / 2]; var R = new int[a.Length - L.Length]; for (int i = 0; i < L.Length; i++) L[i] = a[i]; for (int i = 0; i < R.Length; i++) R[i] = a[i + L.Length]; if (L.Length > 1) L = MergeSort(L); if (R.Length > 1) R = MergeSort(R); a = Merge(L, R); } return a; } static int[] Merge(int[] L, int[] R) { var res = new int[R.Length + L.Length]; int iL = 0; int iR = 0; while (iR + iL < res.Length) if (iR >= R.Length) { res[iL + iR] = L[iL]; iL++; } else if (iL < L.Length && L[iL] < R[iR]) { res[iL + iR] = L[iL]; iL++; } else { res[iL + iR] = R[iR]; iR++; } return res; } } }