import random def qsort2(array): if len(array) <= 1: return array else: return qsort2([i for i in array[1:] if i<array[0]]) + [array[0]] + qsort2([i for i in array[1:] if i>=array[0]]) def qsort(array, left, right): if left >= right: pass else: print array,left,right low = left+1 high = right index = left while low <= high: while low<=high and array[low]<array[index]: low += 1 while low<=high and array[high]>=array[index]: high -= 1 if low<high: array[low],array[high] = array[high],array[low] if high > index: array[index],array[high]=array[high],array[index] print array, high print qsort(array, left, high-1) qsort(array, high+1, right) x = [random.randint(0,100) for i in range(10)] print x qsort(x,0,9) print x