The Hill sort (Shell sort) is a sort of insertion. Also known as narrowing incremental sorting, is a more efficient and improved version of the direct insertion sorting algorithm. Hill Sort is a non-stable sorting algorithm.
Hill sort is to group records by a certain increment of the subscript, sorting each group using the direct insertion sorting algorithm; As the increments gradually decrease, each group contains more and more keywords, when the increment is reduced to 1 o'clock, the entire file is divided into a group, the algorithm terminates
Because of the number of insertions, we know that one insert sort is stable and does not change the relative order of the same elements, but in different insertion sorts, the same elements may move in their own insert sort, and finally their stability will be disturbed, so the shell sort is unstable.
Code:
void Shellsort (struct sq_list *v) {int I, j, gap, n = v->length;for (gap = N/2; gap > 0; Gap/= 2) for (i = gap; I < n; i++) for (j = i-gap; J >= 0 && v->elem[j].id > v->elem[j + gap].id; J-= Gap) Swap (v->elem[j].id, V ->elem[j + gap].id);}
Classic Sorting algorithm---hill sort