快速排序 python实现代码

时间:2021-04-13 10:04:11
【文件属性】:
文件名称:快速排序 python实现代码
文件大小:721B
文件格式:TXT
更新时间:2021-04-13 10:04:11
快速排序 function quick_sort(s, _begin, _end) if _begin < _end then i = _begin j = _end pivot = s[j] while i < j do while(i < j and s[i] <= pivot) do i = i + 1 end if i < j then s[j] = s[i] end while(i < j and s[j] >= pivot) do j = j - 1 end if i < j then s[i] = s[j] end end s[j] = pivot; quick_sort(s, _begin, i - 1) quick_sort(s, i + 1, _end) end end function prints (s) local tmp = '' for i = 1,#a do tmp = tmp..a[i].." " end print(tmp) end a = {11,5,25,8,2,95,10,7} quick_sort(a,1,#a) prints(a)

网友评论