package com.zhonghaiwangluokeji.interview; /** * 实现冒泡排序 * @author yangjianzhou * */ public class Problem1 { public static void main(String[] args) { int [] xx = {8,4,2,6,3,9,10,2,34,4}; xx = bubSort(xx); for(int i=0;i<xx.length;i++){ System.out.print(xx[i]+" "); } } public static int[] bubSort(int[] a){ int temp; int len = a.length; for(int i=0;i<len;i++){ for(int j=len-1;j>i;j--){ if(a[j]<a[j-1]){ temp = a[j-1]; a[j-1] = a[j]; a[j] = temp; } } } return a; } }
2 2 3 4 4 6 8 9 10 34