数据结构--排序--快排and冒泡(python)

听说大厂面试,限时两分钟写出来快排。。。

闲着没事,写了一下。。。

 def Partition(L,low,high):
pivotkey = L[low]
while low<high:
while low<high and L[high]>=pivotkey:
high-=1
L[low],L[high]=L[high],L[low]
while low<high and L[low]<=pivotkey:
low+=1
L[low],L[high]=L[high],L[low]
return low
def Qsort(L,low,high):
if low < high:
pivot = Partition(L,low,high)
Qsort(L,low,pivot-1)
Qsort(L,pivot+1,high)

冒泡:

 def bubbleSort(nums):
for i in range(len(nums)):
for j in range(len(nums)-1,i,-1):
if nums[j] < nums[j-1]:
temp = nums[j]
nums[j] = nums[j-1]
nums[j-1]=temp
return nums
上一篇:解决终端SSH连接服务器一段时间不操作之后卡死的问题


下一篇:.NET NLog 详解(二)