sortvis.org


sorting algorithm visualisation

combsort

+
-
1:1
[ ]
drag to pan, scroll to zoom, view raw

code

def combsort(lst):
    gap = len(lst)
    swaps = False
    while 1:
        gap = int(gap / 1.25)
        swaps = False
        for i in xrange(len(lst) - gap):
            if lst[i] > lst[i + gap]:
                lst[i], lst[i + gap] = lst[i + gap], lst[i]
                lst.log()
                swaps = True
        if not swaps and gap <= 1:
            break

List order is sampled for visualisation whenever lst.log() is called.

Copyright 2010 Aldo Cortesi