`
ldsjdy
  • 浏览: 147480 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

冒泡排序

阅读更多

 public static void main( String[] args )
    {
        int[] a = new int[]{1,2,5,3,7,9,6};
        for(int i =0 ; i < a.length;i++){
        	System.out.println(Arrays.toString(a));
        	for(int j = 0;j < a.length-i-1;j++){
        		if(a[j] > a[j+1]){
        			int temp = a[j];
        			a[j] = a[j+1];
        			a[j+1]=temp;
        		}
        	}
        }
     
    }


[1, 2, 5, 3, 7, 9, 6]
[1, 2, 3, 5, 7, 6, 9]
[1, 2, 3, 5, 6, 7, 9]
[1, 2, 3, 5, 6, 7, 9]
[1, 2, 3, 5, 6, 7, 9]
[1, 2, 3, 5, 6, 7, 9]
[1, 2, 3, 5, 6, 7, 9]

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics