定义一个1*10的数组[5 9 4 2 3 10 18 12 11 7],利用冒泡法进行由小到大排序,要求使用自定义函数完成

2025-04-13 20:33:59
推荐回答(3个)
回答1:

public class Sort {

public Sort() {
// TODO Auto-generated constructor stub
}

public void maoPao(int[] a) {
int temp = 0;
for (int i = a.length - 1; i > 0; --i) {
for (int j = 0; j < i; ++j) {
if (a[j + 1] < a[j]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}

public static void main(String[] args) {
int[] x = { 5, 9, 4, 2, 3, 10, 18, 12, 11, 7 };
Sort s = new Sort();
s.maoPao(x);
for (int i = 0; i < x.length; i++) {
System.out.print(x[i] + " ");
}

}
}

回答2:

请说明所用语种。

回答3:

JAVA?