void QuickSort(vector<int> &nums,vector<int>::iterator left,vector<int>::iterator right)
{
vector<int>::iterator i;
vector<int>::iterator j;
int pivot;
if (left + Cutoff <= right)
{
pivot = Median3(nums, left, right);
i = left;
j = right - 1;
for (;;)
{
while (*(++i) < pivot){
}
while (*(--j) > pivot){
}
if (i < j)
{
std::iter_swap(i, j);
}
else
{
break;
}
}
std::iter_swap(i, right - 1);
QuickSort(nums, left, i - 1);
QuickSort(nums, i + 1, right);
}
else
{
vector<int>::iterator it_temp1 = nums.begin();
vector<int>::iterator it = nums.begin();
int temp = 0;
for (it_temp1 = left; it_temp1 <= (right - left);++it_temp1)
{
temp = *it_temp1;
for (it = it_temp1; it > nums.begin() && *(it - 1) > temp;--it)
{
*it = *(it - 1);
}
*it = temp;
}
}
}
详细情况见于上图。为什么left和right这两个迭代器就可以比较大小,而it_temp1就无法和(right-left)比较呢?
我自己也上网查了不少还把c++primer这一节重看了,但实在找不出问题所在,希望这里能有人帮我详细解答一下。