C / C ++ to achieve quick sort

. 1 #include <the iostream>
 2  the using  namespace STD;
 . 3  void qS ( int * Array, int left, int right) {
 . 4    IF (left <right) {     // termination condition quicksort, when only a left end of the element quicksort 
. 5      int Key = Array [left];
 . 6      int Low = left, High = right;
 . 7      the while (Low < High) {
 . 8        the while (Key <= Array [High] && Low <High) {     // . 8 ~. 11 operation compare elements sequentially from the right to the left, the left element is placed below the target value 
. 9          high-- ;
 10        }
. 11        Array [Low] = Array [High];
 12 is        the while (Key> = Array [Low] && Low <High) {     // 12 is ~ 15 operations are compared in turn from the left to the right of the element, the element will be greater than the target value at the right side 
13 is          Low ++ ;
 14        }
 15        Array [High] = Array [Low];
 16      }
 . 17      Array [Low] = Key;               // will be placed in the target space, the end of this time a quick sort, are all less than the target value of the left his right is greater than all of its 
18      qS (Array, left, LOW- 1 );        // the target element set and then left quickly sort 
19      qS (Array, Low + 1 , right);       // the target value right element set again quickly sort 
20    }
 21 }
22 
23 int main() {
24   int arr[]={33,14,2,444,23,444,132,55,0};
25   qS(arr,0,sizeof(arr)/sizeof(arr[0]-1));
26   for(int i=0;i<sizeof(arr)/sizeof(arr[0]);++i){
27     cout<<arr[i]<<' ';
28     }
29   return 0;
30 }

Guess you like

Origin www.cnblogs.com/Kaniso-Vok/p/12026876.html