QuickSort

 1 #include<iostream>
 2 
 3 
 4 using namespace std;
 5 
 6 void Repeat(int* a,int Left,int Right);
 7 int QuickSort(int* a,int Left,int Right);
 8 
 9 
10 void main()
11 {
12     int a[5] = {9,1,2,8,4}; 
13 
14     Repeat(a,0,4);
15 
16     int i = 0;
17 
18     for(i=0;i<5;i++)
19     {
20         cout<<a[i]<<" ";
21     
22     
23     }
24     cout<<endl;
25 
26 
27 
28 }
29 void Repeat(int* a,int Left,int Right)
30 {
31     int m = 0;
32     if(Left<Right)
33     {
34         m = QuickSort(a,Left,Right);
35         
36         Repeat(a,Left,m-1);
37 
38         Repeat(a,m+1,Right);
39     
40     }
41 
42 
43 }
44 int QuickSort(int* a,int Left,int Right)
45 {
46     int Temp = a[Left];
47     while(Left<Right)
48     {
49         while(Left<Right&&Temp<=a[Right])     
50         {
51             Right--;
52         
53         
54         }
55         a[Left] = a[Right];
56 
57         while(Left<Right&&Temp>=a[Left])
58         {
59         
60             Left++;
61         
62         }
63         a[Right] = a[Left];
64         a[Left] = Temp;
65     
66     }
67 
68     return Left;
69 
70 }

 

转载于:https://www.cnblogs.com/icqw/p/3744783.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值