python版本的快速排序

'''
Created on 2013-7-10

@author: fpc
'''
def position(sequence,left,right):
    i = left
    j = right
    if i >= j:
        return 
    temp = sequence[left]
    while i < j :
        while i < j and sequence[j] >= temp:
            j -= 1
        sequence[i] = sequence[j]
        while i < j and sequence[i] < temp:
            i += 1
        sequence[j] = sequence[i]
    sequence[i] = temp
    return i

def quickSort(sequence,left,right):
    if left >= right:
        return
    mid=position(sequence,left,right)
    quickSort(sequence,left,mid-1)
    quickSort(sequence,mid+1,right)
    
sequence = input().split(" ")
print(type(sequence[0]))
print("the sequence number you input:")
print(sequence)
length=len(sequence)
quickSort(sequence,0,length-1)
print("the sorted sequence:")
print(sequence)

你可能感兴趣的:(python版本的快速排序)