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( ???,???);

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.

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.

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 ;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.