Java 삽입정렬 구현

1 개요[ | ]

Java 삽입정렬 구현
public class MyClass {
    static void insertion_sort(int a[]) {
        int i, j, temp, size = a.length;
        for(i=1; i<size; i++) {
            temp = a[i];
            for(j=i-1; j>=0; j--) {
                if(a[j]<temp) break;
                a[j+1] = a[j];
            }
            a[j+1] = temp;
        }
    }
    public static void main(String args[]) {
    	int[] arr = {9,1,22,4,0,-1,1,22,100,10};
    	insertion_sort(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 }}