快速排序算法(7)

1.理论参见:http://blog.sina.com.cn/s/blog_73428e9a01017f9x.html

2.c代码

/*************************************************************************
	> File Name: quickSort.c
	> Author:NULL 
	> QQ:    574889524
	> Created Time: 2014年10月16日 星期四 16时42分06秒
 ************************************************************************/

#include<stdio.h>
#define ARRSIZE 8
/************************************************************************/
void ExChangeInt(int *a,int *b)  
{  
    int iTemp = *a;  
    *a = *b;  
    *b = iTemp;  
} 

void PrintArrInt(int *a,int iLarg)  
{  
    int i;  
    for(i = 0;i < iLarg;++i)  
        printf("%d ",a[i]);  
    printf("\n");  
} 
/************************************************************************/

int Partition(int *A,int p,int r)
{
    int j,x,i;
    x = A[r];
    i = p - 1;
    for(j = p;j<=r-1;j++){
        if(A[j] <=x){
            i++;
            ExChangeInt(&A[i],&A[j]);
        }
    }
    ExChangeInt(&A[i+1],&A[r]);
    return i + 1;
}


void QuickSort(int *A,int p,int r)
{
    int q;
    if(p<r){
        q = Partition(A,p,r);
        QuickSort(A,p,q-1);
        QuickSort(A,q+1,r);
    }
}
/************************************************************************/
int main()
{
    int A[ARRSIZE] = {2,8,7,1,3,5,6,4};
    QuickSort(A,0,ARRSIZE-1);
    PrintArrInt(A,ARRSIZE);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

byd yes

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值