자바 거품 정렬 단일 순환

오늘 동반 면접 에서 동료 가 단일 순환 거품 순 서 를 물 어 시험 에 합격 했다!스스로 돌아 와 서 시험 해 보 았 는데 코드 는 다음 과 같다.
 
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] + ",");     
		}
	}

 

좋은 웹페이지 즐겨찾기