C++ 빗질정렬 구현

1 개요[ | ]

C++ 빗질정렬 구현
#include <iostream>
void comb_sort(int a[], int size) {
    int i, temp, gap;
    bool swapped = true;
    while( gap!=1 || swapped ) {
        gap = gap*10/13;
        if( gap<1 ) gap=1;
        swapped = false;
        for( i=0; i<size-gap; i++ ) {
            if( a[i] > a[i+gap] ) {
                temp=a[i]; a[i]=a[i+gap]; a[i+gap]=temp;
                swapped = true;
            }
        }
    }
}
int main() {
    int arr[] = {9,1,22,4,0,-1,1,22,100,10};
    int size = sizeof(arr)/sizeof(int);
    comb_sort(arr, size);
    for(int x: arr) std::cout << x << " ";
    // -1 0 1 1 4 9 10 22 22 100 
}

2 같이 보기[ | ]

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