AI智能
改变未来

C#数组的排序

class Program{static void Main(string[] args){int[] list = { 34, 72, 13, 44, 25, 30, 10 };Console.WriteLine(\"原始数组\");for (int i=0;i < list.Length;i++){Console.WriteLine(list[i]);}Array.Sort(list);Console.WriteLine(\"Array.Sort排序后数组\");for (int i = 0; i < list.Length; i++){Console.WriteLine(list[i]);}Array.Reverse(list);Console.WriteLine(\"Array.Reverse逆转数组\");for (int i = 0; i < list.Length; i++){Console.WriteLine(list[i]);}Console.WriteLine(\"冒泡排序后\");int[] array = { 34, 72, 13, 44, 25, 30, 10 };int temp = 0;for (int i = 0; i < array.Length - 1; i++){for (int j = i + 1; j < array.Length; j++){if (array[j] < array[i]){temp = array[i];array[i] = array[j];array[j] = temp;}}}for (int i = 0; i < array.Length; i++){Console.WriteLine(array[i]);}}}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » C#数组的排序