码迷,mamicode.com
首页 > 其他好文 > 详细

QuickSort

时间:2014-05-22 14:53:10      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

bubuko.com,布布扣
 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 }
bubuko.com,布布扣

 

QuickSort,布布扣,bubuko.com

QuickSort

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/Big-Maker/p/3744783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!