#!/usr/bin/env python
# -*- coding: utf-8 -*-

def quick_sort(a):
    _quick_sort(a, 0, len(a)-1)
    return a


def _quick_sort(a, lo, hi):

    if lo < hi:
        j = partition(a, lo, hi)
        _quick_sort(a, lo, j-1)
        _quick_sort(a, j+1, hi)

def partition(a, lo, hi):

    # simply select first element as pivot
    #   or use sorted(low, midum, high)[1] as pivot,
    #       and exchange with a[lo]
    pivot = a[lo]

    border = lo
    for i in range(lo, hi + 1):
        if a[i] < pivot:
            border +=1
            a[i], a[border] = a[border], a[i]
    a[lo], a[border] = a[border], a[lo]

    return border

if __name__ == '__main__':
    d = [34,2,24,12, 45,33,9,99]
    print quick_sort(d)

@@ -164,32 +164,33 @@
    j = partition
+2
 (a, lo, hi)%0A    
@@ -630,16 +630,332 @@
 border%0A%0A
+def partition2(a, lo, hi):%0A%0A    pivot = a%5Blo%5D%0A    l = lo%0A    h = hi%0A    while True:%0A        while a%5Bl%5D %3C pivot and l %3C hi:%0A            l += 1%0A        while a%5Bh%5D %3E pivot and h %3E lo:%0A            h -= 1%0A%0A        if l %3E= h:%0A            break%0A        a%5Bl%5D, a%5Bh%5D = a%5Bh%5D, a%5Bl%5D%0A    a%5Blo%5D, a%5Bl%5D = a%5Blo%5D, a%5Bl%5D%0A%0A    return l%0A%0A%0A
 if __nam

add a new partition function