冒泡排序

来源:互联网 发布:淘宝做分销有成功的吗 编辑:程序博客网 时间:2024/06/15 22:13
public class bubbleSort {


public static void main(String[] args) {


int a[] = { 329, 78, 23, 2424, 5, 90, 354, 98 };
int temp = 0;
for (int i = 0; i < a.length - 1; i++) {
for (int j = 0; j < a.length - 1 - i; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}


for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
}
原创粉丝点击