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

    /*
     * =====================================================================================
     *
     *       Filename:  QuickSort.c
     *
     *    Description:  
     *
     *        Version:  1.0
     *        Created:  2014年06月11日 21时30分51秒
     *       Revision:  none
     *       Compiler:  gcc
     *
     *         Author:  Wenxian Ni (Hello World~), niwenxianq@qq.com
     *   Organization:  AMS/ICT
     *
     * =====================================================================================
     */
    
    #include<stdio.h>
    
    void swap(int *p, int *q)
    {
        int temp = *p;
        *p = *q;
        *q = temp;
    }
    int GetPos(int *p, int start, int end)
    {
        int posData = *(p+start);
        while(start<end)
        {
            while(start<end&&*(p+end)>=posData)
                end--;
            if(end!=start)
            {
                *(p+start) = *(p+end);
                start++;
                while(start<end&&*(p+start)<=posData)
                    start++;
                if(start!=end)
                {
                    *(p+end) = *(p+start);
                    end--;
                }
            }
        }
        *(p+end) = posData;
        return end;
    }
    
    void QuickSort(int *p, int start, int end)
    {
        if(start >= end)
            return ;
        int pos = GetPos(p, start, end);
        QuickSort(p, start, pos-1);
        QuickSort(p, pos+1, end);
        return ;
    }
    
    int main()
    {
    
        int a[10];
        int n;
        int i;
        while(~scanf("%d",&n))
        {
            for(i=0;i<n;i++)
            scanf("%d",&a[i]);
            QuickSort(a,0,n-1);
            for(i=0;i<n;i++)
            printf("%d ",a[i]);
        }
        return 0;
    }
    

    每天早上叫醒你的不是闹钟,而是心中的梦~
  • 相关阅读:
    类和对象的一些BIF
    mac入门--通过hhomebrew下载过慢问题
    Vue的组件及传参
    Vue的指令和成员
    Vue基础(1)
    Python中好用的模块们
    Django-Auth认证模块
    Django杂篇(2)
    Django杂篇(1)
    Django的日常-AJAX
  • 原文地址:https://www.cnblogs.com/vintion/p/4116872.html
Copyright © 2011-2022 走看看