"Java 쉘정렬 구현"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
3번째 줄: 3번째 줄:
;자바 쉘정렬 구현
;자바 쉘정렬 구현


<source lang='java'>
<syntaxhighlight lang='java'>
public class MyClass {
public class MyClass {
     static void shellSort(int[] a) {
     static void shellSort(int[] a) {
28번째 줄: 28번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:50 기준 최신판

1 개요[ | ]

Java 쉘정렬 구현
자바 쉘정렬 구현
public class MyClass {
    static void shellSort(int[] a) {
    	int i, j, temp, size = a.length;
    	int gap = size / 2;
    	while( gap > 0 ) {
    	    for( i=gap; i<size; i++ ) {
    	        temp = a[i];
    	        j = i;
    	        while( j>=gap && a[j-gap]>temp ) {
    	            a[j] = a[j-gap];
    	            j -= gap;
    	        }
    	        a[j] = temp;
    	    }
    	    gap /= 2;
    	}
    }
    public static void main(String args[]) {
    	int[] arr = {9,1,22,4,0,-1,1,22,100,10};
    	shellSort(arr);
    	for(int x: arr) System.out.format( "%d ", x );
    	// -1 0 1 1 4 9 10 22 22 100 
    }
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}