zoukankan      html  css  js  c++  java
  • 快速排序

    1. #include <cstdio>  
    2. #define ARRLEN(x) (sizeof(x)/sizeof(int))  
    3. int partition(int a[], int low, int high)  
    4. {  
    5.     int pivotkey=a[low];  
    6.     while (low<high)  
    7.     {  
    8.         while (low<high && a[high]>=pivotkey)  
    9.             --high;  
    10.         if (low<high)   
    11.             a[low++]=a[high];  
    12.         while (low<high && a[low]<=pivotkey)  
    13.             ++low;  
    14.         if (low<high)   
    15.             a[high--]=a[low];  
    16.     }  
    17.     a[low]=pivotkey;  
    18.     return low;  
    19. }  
    20. void quicksort(int a[], int low, int high)  
    21. {  
    22.     int pivotpos;  
    23.     if (low<high)  
    24.     {  
    25.         pivotpos=partition(a,low,high);  
    26.         quicksort(a,low,pivotpos-1);  
    27.         quicksort(a,pivotpos+1,high);  
    28.     }  
    29. }  
    30. int main()  
    31. {  
    32.     int a[]={2,7,9,3,1,4,8,0,6,2};  
    33.     int i;  
    34.     for (i=0; i<ARRLEN(a); printf("%2d",a[i]),++i);  
    35.     printf("/n");  
    36.     quicksort(a,0,ARRLEN(a)-1);  
    37.     for (i=0; i<ARRLEN(a); printf("%2d",a[i]),++i);  
    38.     printf("/n");  
    39.     return 0;  
    40. }  
  • 相关阅读:
    Ubuntu16.04 + CUDA 8.0 (GTX 1050ti)
    关于MapD的集群建立
    2-7 单位和坐标系
    2-6 光线投射
    2-5 事件系统(Event System)
    2-4 Rect Transform(矩形)组件的属性
    2-3 RectangleTransform矩形组件
    2-2 Graphic Raycasrer组件(光线投射)
    2-1 Ui元素-画布
    1-5 事件方法的执行顺序
  • 原文地址:https://www.cnblogs.com/small-strong/p/3922276.html
Copyright © 2011-2022 走看看