01. Example:
def combSorting(data): def swap(i, j): data[i], data[j] = data[j], data[i] gap = len(data) shrink = 1.3 flag = False while not flag: gap = int(gap/shrink) if gap < 1: gap = 1 flag = True else: flag = False i = 0 while i + gap < len(data): if data[i] > data[i + gap]: swap(i, i + gap) flag = False i = i + 1 list01 = input('Enter the list of numbers: ').split() list01 = [int(x) for x in list01] combSorting(list01) print('nSorted list: ', end='') print(list01)
Output:
Enter the list of numbers: 320 420 140 500 185 60 200 80 10 100
Sorted list: [10, 60, 80, 100, 140, 185, 200, 320, 420, 500]