C examples for Data Structure:Sort
Create function for shell short
#include <stdio.h> /* shellsort: sort v[0]...v[n-1] into increasing order */ void shellsort(int v[], int n) { int gap, i, j, temp; for (gap = n / 2; gap > 0; gap /= 2) for (i = gap; i < n; i++) for (j = i - gap; j >= 0 && v[j]>v[j + gap]; j -= gap) { temp = v[j];/*from w ww . j ava 2 s . com*/ v[j] = v[j + gap]; v[j + gap] = temp; } } int main() { int i, n = 0, in[10]; printf("input 5 number for shell sort. ctrl + D to exit:"); while (scanf("%d", &in[n]) != EOF) n++; shellsort(in, n); for (i = 0; i < n; i++) printf("%d\n", in[i]); return 0; }