Making CombSort ranged

I just made some tweaks to the combsort. Basically, my version will now sort over a range of the array. You give it a start index, and then you give it how many integers from that index (including that index) you want to sort. The new code looks something like this:

void combsort_ranged(int * input, unsigned start, unsigned len, int (*comparison)(int *s0, int *s1))
{
    unsigned end = start + len;
    unsigned gap = len;
    unsigned int swaps = 0xFFFF;

    while(gap > 1 || swaps != 0)
    {
        if (gap > 1)
        {
            gap /= 1.3;
            if (gap == 10 || gap == 9)
                gap = 11;
        }

        unsigned i = start;
        swaps = 0;

        while (i + gap < end)
        {
            if (comparison(&(input[i]), &(input[i + gap])) > 0)
            {
                // Swap input[i] and input[i + gap]
                int temp = input[i];
                input[i] = input[i + gap];
                input[i + gap] = temp;
                swaps = 1;
            }

            i++;
        }
    }
}

0 Responses to “Making CombSort ranged”


  1. No Comments

Leave a Reply

You must login to post a comment.