zoukankan      html  css  js  c++  java
  • 快排_C实现

    #include<stdio.h>

    int Partition(int A[], int low, int high){ int pivot; pivot = A[low]; while(low < high){ while(low < high && A[high] >= pivot)// 1.相等不替换 2.不要遗漏low < high的判断 high--; A[low] = A[high]; while(low < high && A[low] <= pivot) low++; A[high] = A[low]; } A[low] =pivot; return low; } void Qsort(int A[], int low, int high){ int pivot; if(low < high){//不要写成 while 导致死循环 pivot = Partition(A ,low, high); Qsort(A, low, pivot-1); Qsort(A, pivot+1, high); } } void QuickSort(int A[], int n){ Qsort(A, 0, n-1); } int main(){ int A[15]={5,6,4,3,2,6,4,4,6,5,3,22,6,1,-23}; QuickSort(A, 15); for(int i=0; i<15; i++) printf("%d ", A[i]); return 0; }

  • 相关阅读:
    学习进度条
    学术诚信与职业道德
    czxt
    操作系统
    04 17评论博客
    0414 结对 2.0 33 34
    0408 汉堡包
    (补)结对心得
    构建之法4读后感
    复利计算4.0
  • 原文地址:https://www.cnblogs.com/exciting/p/10058013.html
Copyright © 2011-2022 走看看