C언어 쉘정렬 구현

(C 쉘정렬 구현에서 넘어옴)

1 개요[ | ]

C언어 쉘정렬 구현
#include <stdio.h>
void shell_sort(int a[], int size) {
    int i, j, temp;
    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;
    }
}
int main() {
	int arr[] = {9,1,22,4,0,-1,1,22,100,10};
	int size = sizeof(arr)/sizeof(int);
	shell_sort(arr, size);
	for(int i=0; i<size; i++) printf("%d ", arr[i]);
	// -1 0 1 1 4 9 10 22 22 100 
}

2 같이 보기[ | ]

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