ProAnswers.org

algorithm Shell Sort

algorithm Shell Sort

#define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t))

	void shell_sort(int list[], int length){

	    int gap, i, j, temp;

	    for(gap = length / 2; gap > 0; gap /= 2){

	        for(i = gap; i < length; i++){

	            for(j = i - gap; j >= 0 && list[j] > list[j + gap]; j -= gap)

	                SWAP(list[j], list[j + gap], temp);

	        }

	    }

	}