zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    学习第23天
    学习第22天
    学习第21天
    Servlet交互与JSP
    Cookie与Session
    servlet入门
    网络编程
    DOM4j
    xml文档对象模型doc
    反射
  • 原文地址:https://www.cnblogs.com/icqw/p/3744783.html
Copyright © 2011-2022 走看看