面试之冒泡排序

来源:互联网 发布:linux mmap 文件 编辑:程序博客网 时间:2024/05/21 13:23
public void bubbleSort() {
int a[] = { 8,4,6,7,5,1};
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.println(a[i]);

}


http://blog.csdn.net/yyywyr/article/details/8075433



1 0
原创粉丝点击