기수 정렬 (C 언어 + 배열 구현)

1191 단어 데이터 구조
int radixSort(int *arr, int low, int high, int radix) { /*      <= 10    ,          */
    if (!arr) /*     NULL,   1*/
        return 1;
    if (low < high) {
        int power = 1, significant = 1;
        while (significant) { /*         ,   */
            significant = 0;
            int pipes[radix][high - low + 1],
                pipeLength[radix]; /*       */
            for (int i = 0; i < radix; ++i) { /* C99              */
                pipeLength[i] = 0; /*                     ,         */
            }
            /*       */
            for (int i = low; i <= high; ++i) {
                int rad = (arr[i] / power) % radix; /*         */
                if (arr[i] / power)
                    significant = 1; /*      */
                pipes[rad][pipeLength[rad]++] = arr[i]; /*            */
            }
            /*          */
            int k = low; /*            */
            for (int i = 0; i < radix; ++i) {
                for (int j = 0; j < pipeLength[i]; ++j) {
                    arr[k++] = pipes[i][j]; 
                }
            }
            power *= radix;
        }
    }
    return 0;
}

좋은 웹페이지 즐겨찾기