5Python全栈之路系列之算法
#!/usr/bin/env python# _*_ coding: utf-8 _*_
from random import randint
li =
def quick_sort(List, start, end):
print(List, start, end)
if start >= end:
return
Key = List# 值
LeftIndex = start# 左边
RightIndex = end# youbian
while LeftIndex < RightIndex:#
while LeftIndex < RightIndex and List > Key:# 代表要继续往左边移动小旗子
RightIndex -= 1
List, List = List, List
while LeftIndex < RightIndex and List <= Key:# 左边小旗子开始向右移动
LeftIndex += 1
List, List = List, List
quick_sort(List, start, LeftIndex - 1)# 左边
quick_sort(List, LeftIndex + 1, end)
quick_sort(li, 0, len(li) - 1)
print(li)
页:
[1]