阅读背景:

java 冒泡排序 单循环

来源:互联网 

今天陪伴事面试,同事问到了单重复冒泡排序,考住了!自己回来试了一下,代码以下所示:

 

public static void main(String[] args) {
		int [] stars = {10,2,21,9,7,6,12,8,1,98,27,32,11,14,11};
		int temp = 0;
		int lengths = stars.length-1;
		for(int j=0 ; j<lengths ; j++){
	        if(stars[j] > stars[j + 1]){  
	            temp = stars[j];  
	            stars[j] = stars[j+1];  
	            stars[j+1] = temp;  
	        }
			if(j == lengths - 1){
				lengths = lengths - 1;
				j = -1;
			}
		}
		for(int a = 0 ; a < stars.length ; a++)  
	        System.out.print( stars[a] + ",");     
		}
	}publi




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: