I'm trying to write my own quick sort, and its not wanting to work, what wrong?
Code:
void quick_sort(int *a, int size, bool (*cmp) (int, int))
{
int p = partition(a,size,cmp);
int lhs=(p+1);
int rhs= (size-(p+1));
if(lhs>1)
quick_sort(a, lhs, cmp);
if(rhs>1)
quick_sort(a+(p+1), rhs, cmp);
}
int partition(int* a, int size, bool (*cmp) (int, int))
{
int p=0, oe=(size-1), temp=0;
while(p!=oe)
{
while(p<oe)
{
if(cmp(a[p],a[oe]))
{
temp=a[p];
a[p]=a[oe];
a[oe]=temp;
temp=p;
p=oe;
oe=temp;
oe++;
}
else
{
oe--;
}
}
while(p>oe)
{
if(cmp(a[oe],a[p]))
{
temp=a[p];
a[p]=a[oe];
a[oe]=temp;
temp=p;
p=oe;
oe=temp;
oe++;
}
else
{
oe++;
}
}
}
return p;
}