Construye una funcion que implemente el algoritmo de ordenamiento rapido. La funcion de particion() ha sido predefinida y se muestra a continuacion.
Considera que datos es una lista, primero es el indice del primer elemento y ultimo es el indice del ultimo elemento.
def partition(data, first, last):
pivot_value = data[first]
left_mark = first+1
right_mark = last
done = False
while not done:
while left_mark <= right_mark and data[left_mark] <= pivot_value:
left_mark = left_mark + 1
while data[right_mark] >= pivot_value:
right_mark = right_mark-1
if right_mark < left_mark:
done = True
else:
temp = data[left_mark]
data[left_mark] = data[right_mark]
data[right_mark] = temp
temp = data[first]
data[first] = data[right_mark]
data[right_mark] = temp
return right_mark