def Partition(a,s,t): i=s j=t temp=a[s] while(i<j): while(j>i and a[j]>=temp): j-=1 a[i]=a[j] while(j>i and a[i]<=temp): i+=1 a[j]=a[i] a[i]=temp return i def QuickSort(a,s,t): if(s<t): i=Partition(a,s,t) QuickSort(a,s,i-1) QuickSort(a,i+1,t) def disp(a,n): for i in range(n): print(a[i],end=" ") def main(): n=eval(input()) a= input("") a=a.split() num = [int(i) for i in a] QuickSort(num,0,n-1) disp(num,n) main() |
快速排序python代码
最新推荐文章于 2023-02-17 22:49:03 发布