快速排序c语言原代码


//快速排序思想

#include<stdio.h>
//找出数组分界线比关键字小的放在左边,比关键字大的放在右边
int QKpass(int a[],int low,int high)
{
int pos;
int key=a[low];
while(low<high)
{
while(key<a[high]&&low!=high)
{
high--;
}
  
   if(key>a[high]&&low!=high)
{

a[low]=a[high];

low++;

}
while(key>=a[low]&&low!=high)
{
low++;
}
       if(key<a[low]&&low!=high)
{
a[high]=a[low];


high--;
}

}
if(low == high)
{
a[low]=key;
pos=low;
return pos;
}

}
void QKsort(int a[],int low,int high)
{
int pos=0;

if(low<high)
{
pos=QKpass(a,low,high);
//左边
QKsort(a,low,pos-1);
//右边
QKsort(a,pos+1,high);
}

}
void main()
{
int a[8]={48,62,1,77,55,14,35,9};
int low=0;
int i;
int high=7;
    QKsort(a,low,high);
for(i=0;i<8;i++)
{
printf("%d  ",a[i]);
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值