0

Hi, i am working on a quicksort function and I have everything except how to sort the second half. I am missing one line, where to start the second half and for how many items, any help would be greatly appreciated. THANKS!

int * partition(int array[], int size);

void quicksort(int array[], int size)
{
	if (size == 0)
		return ;
	else
	{
	int * split = partition(array, size);
	quicksort(array, split - array);
	quicksort(  );
	return ;
	}
}

I already have partition prototyped, im just missing quicksort( ???,???);

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by ivailosp
0

int quickSort(int a[],int left,int right)
{
comparisons++;
if (left>=right) return(0);
int q=partition(a,left,right);
quickSort(a,left,q);
quickSort(a,q+1,right);
return(0);}


You must have a left and a right or low-top call it as you like.

That is needed becasue the first partition runs from low until q (or split as you named it) and one more partition runs from q to high . Basically the first half and the second half.

0

Sure, that way does work, but my quicksort function has only two parameters and thats all that it is supposed to have, which is why i am kind of lost.

0

try

int * partition(int array[], int size);

void quicksort(int array[], int size)
{
	if (size == 0)
		return ;
	else
	{
	int * split = partition(array, size);
	quicksort(array, split - array);
        
	quicksort(array+(split - array)+1, split - array );
	return ;
	}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.