shell sort algorithm in python

Solutions on MaxInterview for shell sort algorithm in python by the best coders in the world

showing results for - "shell sort algorithm in python"
Flore
10 Nov 2019
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4
5def shellSort(alist):
6    sublistcount = len(alist)//2
7    while sublistcount > 0:
8      for start_position in range(sublistcount):
9        gap_InsertionSort(alist, start_position, sublistcount)
10
11      sublistcount = sublistcount // 2
12
13def gap_InsertionSort(nlist,start,gap):
14    for i in range(start+gap,len(nlist),gap):
15
16        current_value = nlist[i]
17        position = i
18
19        while position>=gap and nlist[position-gap]>current_value:
20            nlist[position]=nlist[position-gap]
21            position = position-gap
22
23        nlist[position]=current_value
24