Quick Sort 快排
def QuickSort(myList):
if len(myList) > 1:
pviot = myList[0]
low = QuickSort([x for x in myList if x < pviot])
mid = [x for x in myList if x== pviot]
high = QuickSort([x for x in myList if x > pviot])
return(low+mid+high)
else:
return(myList)
python冒泡排序 Bubble Sort
def BubbleSort(List):
flag=True
while flag:
flag=False
x=0
while x <= len(List)-2:
if List[x] > List[x+1]:
temp = List[x]
List[x]=List[x+1]
List[x+1]=temp
flag=True
x=x+1
return(List)