Monday, June 8, 2015

QSort in Python


#! /usr/bin/python

def myqsort(lst):
    if len(lst) <= 1:
        return lst
    p = lst[0]
    return myqsort([x for x in lst if x<p]) + [x for x in lst if x==p] + myqsort([x for x in lst if x>p])


lst = myqsort([1,4,3,4,6,3,2,6,8,3,2,6,9,7])
print lst
 

No comments:

Post a Comment