Answer the question
In order to leave comments, you need to log in
How does the quicksort algorithm work?
Can you describe in detail how this algorithm works?
int partition (int[] array, int start, int end)
{
int marker = start;
for ( int i = start; i <= end; i++ )
{
if ( array[i] < array[end] )
{
int temp = array[marker]; // swap
array[marker] = array[i];
array[i] = temp;
marker += 1;
}
}
return marker - 1;
}
void quicksort (int[] array, int start, int end)
{
if ( start >= end )
{
return;
}
int pivot = partition (array, start, end);
quicksort (array, start, pivot-1);
quicksort (array, pivot+1, end);
}
Answer the question
In order to leave comments, you need to log in
Here's even a video for you https://youtu.be/ywWBy6J5gz8
And so read on the Internet.
A random element is selected on the sorted part of the array, all elements less than it are transferred to the left side, the rest to the right. For each of the parts, a similar algorithm is called. The devil is in the details :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question