while (true) { int.TryParse(Console.ReadLine(), out int N); int[] arr = new int[N]; Random ran = new Random(); for (int i = 0; i < arr.Length; i++) { arr[i] = ran.Next(1, 1000); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Sort(arr); Console.WriteLine ($ "of {N / 2} a large number:" + arr [N / 2 - 1]); stopwatch.Stop(); TimeSpan tp = stopwatch.Elapsed; Console.WriteLine ($ "run: Total ms: {tp.TotalMilliseconds}"); } // descending static int[] Sort(int[] arr) { int temp; for (int i = 0; i < arr.Length - 1; i++) { for (int j = i + 1; j < arr.Length; j++) { if (arr[i] < arr[j]) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } return arr; }
K returns the maximum array index with a most simple, time complexity miserable.