I tried to work on breakpoints so that I can follow how this recursive function in Quicksort Algorithm works.
static public void SortQuick(int[] arr, int left, int right)
{
if (left < right)
{
int pivot = Partition(arr, left, right);
if (pivot > 1)
{
SortQuick(arr, left, pivot - 1);
}
if (pivot + 1 < right)
{
SortQuick(arr, pivot + 1, right);
}
}
}
What I want to know is, what is happening in the process when the 2 inner "if statements" become false. Why the recursion does not terminate? Where the next process will go and why?
I just got confused because when I tried to follow the breakpoints step by step, I didn't understand what really happened. The left = 0 and right = 2, but when I continued to follow the breakpoints, it became left = 5 and right = 9. Anyway, 4 is my first pivot and I entered 10 numbers. So basically, I knew that the code was starting to partition the right side as it's done with left side; That's why the left variable became 5 and the right became 9. I just don't get how this happens and which part of this function made left = 5 and right = 9 from left = 0 and right = 2.
This is what I've entered: (5 1 9 2 3 8 4 7 6 10)
I've already understand the Partition Process, so I didn't include it in my question. Thanks in advance. :)