C#的对数组排序
来源:互联网 发布:hl302u控制卡软件 编辑:程序博客网 时间:2024/05/13 20:57
// int[] list = { 0, 2, 6, 3, 5, 1, 4, 9, 7, 8 }; int[] list = new int[10]; for (int i = 0; i < 10; i++) { list[i] = Convert.ToInt32( Console.ReadLine()); } Console.WriteLine("排序前:"); for (int i = 0; i < list.Length; i++) Console.WriteLine(list[i]); Console.WriteLine(); int tmp = 0; bool isOK = false; while (!isOK) { isOK = true; for (int i = 0; i <= list.Length - 2; i++) { //Console.WriteLine(i); if (list[i ] > list[i+1 ]) { tmp = list[i]; list[i] = list[i + 1]; list[i + 1] = tmp; isOK = false; } } } Console.WriteLine("排序后:"); for (int i = 0; i < list.Length; i++) Console.WriteLine(list[i]); Console.WriteLine();