java 实现冒泡排序

来源:互联网 发布:fliqlo mac 编辑:程序博客网 时间:2024/06/05 20:09
package com;
/**
 * 实现冒泡排序
 * @author 小小王
 *
 */
public class TestBubbleSort {
public static void bubbleSort(int[] a){
int temp = 0;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
if(a[j] < a [i]){
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
}
public static void main(String[] args) {
int a[] = {4,6,2,4,8,5,2,9};
bubbleSort(a);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
原创粉丝点击