Sorting algorithms/Shell sort: Difference between revisions
Content added Content deleted
(commo lisp shell sort) |
m (→{{header|C}}) |
||
Line 141: | Line 141: | ||
int main (int argc, char *argv[]) |
int main (int argc, char *argv[]) |
||
{ |
{ |
||
int intArray[ARRAYSIZE], i, increment; |
int intArray[ARRAYSIZE], i, increment; |
||
for(i=0; i< |
for(i=0; i<ARRAYSIZE; i++) |
||
intArray[i] = rand(); |
intArray[i] = rand(); |
||
shellsort(intArray, ARRAYSIZE); |
|||
} |
} |
||
void shellsort (int a[], int length) |
void shellsort (int a[], int length) |
||
{ |
{ |
||
int i, j, k, temp, increment; |
int i, j, k, temp, increment; |
||
static int incSequence[] = {412771, 165103, 66041, 26417, 10567, |
static int incSequence[] = {412771, 165103, 66041, 26417, 10567, |
||
4231, 1693, 673, 269, 107, 43, 17, 7, 3, 1}; |
4231, 1693, 673, 269, 107, 43, 17, 7, 3, 1}; |
||
Line 157: | Line 157: | ||
{ |
{ |
||
if (incSequence[k]*2 > length) continue; |
if (incSequence[k]*2 > length) continue; |
||
increment = incSequence[k]; |
increment = incSequence[k]; |
||
for (i=increment; i < length; i++) |
for (i=increment; i < length; i++) |
||
{ |
{ |
||
Line 168: | Line 168: | ||
a[j + increment] = temp; |
a[j + increment] = temp; |
||
} |
} |
||
} |
} |
||
}</lang> |
}</lang> |
||