ITeye博客

冒泡排序

ldsjdy · 2014-07-18 16:58 · javaSE · 企业架构 · Markdown



 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]


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。