OP needs to understand how the quicksort algorithm works, then execute the
algorithm by hand, counting the number of comparisons. I would recommend
looking at psuedo-code or at whatever is in OP's notes/textbook instead of
looking at C++ code. Particularly the std::sort() is not all that easy to follow
even for an experienced professional.
on average quick sorts compare the whole array about 3 times.
where as something like selection sort will go through number of times for each element but each iteration is reducing for each value already read.
that website I linked has examples, however they include the code for the animation. so you can remove the animation code, pauses() etc. or just wiki search quicksort.
or: I got this code from the second google link after typing in "C++ quicksort"
the power of googling.... I'm not quite sure what's the deal with line 37, but I'm sure you can figure it out.
-----------------------------------------
void quickSort(int arr[], int left, int right) {
int i = left, j = right;
int tmp;
int pivot = arr[(left + right) / 2];
/* partition */
while (i <= j) {
while (arr[i] < pivot)
i++;
while (arr[j] > pivot)
j--;
if (i <= j) {
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
}
};
/* recursion */
if (left < j)
quickSort(arr, left, j);
if (i < right)
quickSort(arr, i, right);
}