string str = Console.ReadLine();
string[] strArray = str.Split(" ");
int[] intArray = new int[strArray.Length];
for (int i = 0; i < intArray.Length; i++) {
int number = Convert.ToInt32(strArray[i]);
intArray[i] = number;
}
//系统自带排序
//Array.Sort(intArray);
//foreach (int temp in intArray) {
// Console.Write(temp + " ");
//}
//冒泡
bool change = false;
for (int i = 0; i < intArray.Length -1; i++) {
for (int j = 0; j < intArray.Length -1-i; j++) {
if (intArray[j] > intArray[j + 1]) {
int temp = intArray[j];
intArray[j] = intArray[j + 1];
intArray[j + 1] = temp;
change = true;
}
}
if (change == false){
break;
}
}
foreach (int temp in intArray){
Console.Write(temp + " ");
}
C#学习笔记-冒泡排序
最新推荐文章于 2023-03-21 16:18:11 发布