zoukankan      html  css  js  c++  java
  • 8)排序①排序算法之交换排序[2]快速排序

     1 #include<iostream>
     2 using namespace std;
     3 
     4 //************快速排序法*********
     5 int partiton(int array[10],int s,int t,int &cutpoint){
     6     int x=array[s];
     7     int i,j;
     8     i=s;
     9     j=t;
    10     while(i!=j){
    11         while(i<j&&array[j]>x)j--;
    12         if(i<j){
    13             array[i]=array[j];
    14             i++;
    15         }
    16         while(i<j&&array[i]<x)i++;
    17         if(i<j){
    18             array[j]=array[i];
    19             j--;
    20         }
    21     }
    22     array[i]=x;
    23     cutpoint=i;
    24     return 0;
    25 }
    26 
    27 int quick_sort(int array[10],int s,int t){
    28     int i;
    29     if(s<t){
    30         partiton(array,s,t,i);
    31         quick_sort(array,s,i-1);
    32         quick_sort(array,i+1,t);
    33     }
    34     return 0;
    35 }
    36 //************快速排序法*********
    37 
    38 int print(int n,int array[100]){
    39     int i;
    40     for(i=0;i<n;i++){
    41         cout<<array[i]<<" ";
    42     }
    43     cout<<endl;
    44     return 0;
    45 }
    46 
    47 int main()
    48 {
    49     int array[10]={1,4,5,6,7,23,41,34,7,8};
    50     quick_sort(array,0,9);
    51     print(10,array);
    52     return 0;
    53 }
  • 相关阅读:
    HDU
    Hdu 5072 Coprime(容斥+同色三角形)
    HDU
    HTML常用基础标签
    简单session实现
    前端中的 IoC 理念
    怎样做页面界限
    Reset 对象属性
    SQL注入
    js:表单校验(获取元素、事件)
  • 原文地址:https://www.cnblogs.com/minmsy/p/4963277.html
Copyright © 2011-2022 走看看