sortvis.org


sorting algorithm visualisation

oddevensort

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

code

def oddevensort(lst, nloops=2):
    finished = False
    while not finished:
        finished = True
        for n in xrange(nloops):
            for i in xrange(n, len(lst) - 1, nloops):
                if lst[i] > lst[i + 1]:
                    lst[i], lst[i + 1] = lst[i + 1], lst[i]
                    lst.log()
                    finished = False

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

Copyright 2010 Aldo Cortesi