1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void qs (void *&arr, int left, int right, void (*swap) (void *p1, void *p2),
int (*cmp)(void *p1, void *p2), void * (*get) (void *arr,int i))
{
cout<<"-> "; print_p(arr,5,'2'); cout<<endl;
int i=left, j=right;
void *pivot=get(arr,(i+j)/2);
while (i<=j)
{
while (cmp(get(arr,i),pivot)==SMALL)
i++;
while (cmp(get(arr,j),pivot)==1)
j--;
if (i<=j)
{
swap(get(arr,i),get(arr,j));
i++;
j--;
}
}
if (left<j)
qs(arr,left,j,swap,cmp,get);
if (i<right)
qs(arr,i,right,swap,cmp,get);
}
|