|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
void Quicksort(int *, int, int);
int Findpos(int *, int, int);
int main()
{
int i;
int x[8] = {8, 12, 56, 9, 1, 36, 15, 99};
Quicksort(x, 0, 7);
for(i=0; i<8; i++)
{
printf("%d ", x[i]);
}
return 0;
}
void Quicksort(int * pA, int low, int high)
{
int pos;
if(low < high)
{
pos = Findpos(pA, low, high);
Quicksort(pA, low, pos-1);
Quicksort(pA, pos, high);
}
}
int Findpos(int * pA, int low, int high)
{
int p = pA[low];
while(low < high)
{
while(high > low && pA[high]>=p)
--high;
pA[low] = pA[high];
while(high > low && pA[low]<=p)
++low;
pA[high] = pA[low];
}
pA[low] = p;
return high;
}
|
|