Answers for "Shell Sort Algorithm in Python"

0

Shell Sort Algorithm in Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def shellSort(alist):
    sublistcount = len(alist)//2
    while sublistcount > 0:
      for start_position in range(sublistcount):
        gap_InsertionSort(alist, start_position, sublistcount)

      sublistcount = sublistcount // 2

def gap_InsertionSort(nlist,start,gap):
    for i in range(start+gap,len(nlist),gap):

        current_value = nlist[i]
        position = i

        while position>=gap and nlist[position-gap]>current_value:
            nlist[position]=nlist[position-gap]
            position = position-gap

        nlist[position]=current_value
Posted by: Guest on August-22-2021

Python Answers by Framework

Browse Popular Code Answers by Language