#荷兰国旗
#一个数组和一个数 小于放左边 大于放右边 等于放中间
#可以用于加速快排
def NetherlandsFlag(arr,l,r,num):
less = l-1
more = r+1
current = l
while current <more:
if arr[current]<num:
arr[current],arr[less+1]=arr[less+1],arr[current]
current+=1
less+=1
elif arr[current]==num:
current+=1
else:
arr[current],arr[more-1] = arr[more-1],arr[current]
more-=1
return arr
if __name__ == '__main__':
li = [4,3,7,6,5,1,0,2,3,5,4,7,465,1,3,4,5,5]
a = NetherlandsFlag(li,0,len(li)-1,5)
print(a)