首页 > 编程语言 > 详细

快速排序(过程图解)

时间:2019-03-11 21:19:19      阅读:752      评论:0      收藏:0      [点我收藏+]

参考:https://blog.csdn.net/adusts/article/details/80882649

部分修改后代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int a[10];
 4 void quick(int l,int r)
 5 {
 6     if (l>r)
 7         return;
 8     int temp=a[l],i=l,j=r;
 9     while (i!=j)
10     {
11         while (a[j]>=temp&&i<j)
12             j--;
13         while (a[i]<=temp&&i<j)
14             i++;
15         if (i<j)
16         {
17             swap(a[i],a[j]);
18         }
19     }
20     a[l]=a[i];
21     a[i]=temp;
22     quick(l,i-1);
23     quick(i+1,r);
24 }
25 int main()
26 {
27     int n;
28     cin>>n;
29     for (int i=1;i<=n;i++)
30     {
31         cin>>a[i];
32     }
33     quick(1,n);
34     for (int i=1;i<=n;i++)
35         cout<<a[i]<<" ";
36 
37     return 0;
38 }

 

快速排序(过程图解)

原文:https://www.cnblogs.com/hemeiwolong/p/10513187.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!