List<int> list = new List<int>(); list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); int len = list.Count - 1; list.Sort(); list.ForEach(Console.WriteLine); List<int> listLast = new List<int>(); for (int i = len-1; i >=0; i--) { if (i % 2 == 0) { listLast.Add(list.Max()); list.Remove(list.Max()); continue; } listLast.Add(list.Min()); list.Remove(list.Min()); } listLast.ForEach(Console.WriteLine); for (int i = len - 1; i >= 0; i--) { if (i >= (len - 1) / 2) break; if (i % 2 == 0) continue; int temp = list[i]; list[i] = list[len - 1]; list[len - 1] = temp; } Console.ReadKey();
时间: 2024-12-30 04:31:26