The basic idea of Hill Sorting: Hill sorting is based on the improvement of insert sorting, because the insert sorting is efficient for sorted series operations, but insert sorting is generally inefficient, because only one digit can be moved at a time. Therefore, the Hill sort is first sorted by group until the group increment is 1. Example: arr [,]. when the group increment is 5, the red number is a group, which is inserted in the order and cyclically traversed by arr [13, 3... the basic idea of Hill sorting:
Hill sorting is based on the improvement of insert sorting. because insert sorting is efficient for sorted series operations, insert sorting is generally inefficient because only one bit can be moved at a time. Therefore, the Hill sort is first sorted by group until the group increment is 1.
Example:
Arr = [,]. when the group increment is 5, the red number is a group, which is sorted by insertion and cyclically traversed in turn.
Arr = [,]. after traversal is completed, the group is incrementally auto-subtracted,
Arr = [,], and then insert and sort groups whose group increment is 2 until the group increment is 1.
Code:
Python code
Def shell_sort (lists ):
# Hill Sorting
Count = len (lists)
Step = 2
Group = count/step
While group> 0: # loop through group incremental grouping
For I in range (0, group ):
J = I + group
While j <count: # index of the key value in the group, incremental auto-increment
K = j-group
Key = lists [j]
While k> = 0: # Sort inserts in groups
If lists [k]> key:
Lists [k + group], lists [k] = lists [k], key
Else: break
K-= group
J + = group
Group/= step
Return lists