有关书上某段排序的代码有疑义
//from为a的起始位置,to为末尾位置void merge(vector<int>& a,int from,int mid, int to)
{
int n = to - from -1;
vector<int> b(n);
int i1 = from;
int i2 = mid + 1;
int j =0;
while(i1<=mid && i2<=to)
{
if(a[i1]<a[i2])
{
b[j]=a[i1];
i1++;
}
else
{
b[j] = a[i2];
i2++;
}
j++;
}
while(i1 <=mid )
{
b[j] = a[i1];
i1++;
j++;
}
while(i2<=to)
{
b[j] = a[i2];
i2++;
j++;
}
for(j=0;j<n;j++)
a[from + j] = b[j];
}
void merge_sort(vector<int>& a,int from,int to)
{
if(from == to)return;
int mid = (from+ to)/2;
merge_sort(a,from,mid);
merge_sort(a,mid+1,to);
merge(a,from,mid,to);
}
对于函数merge_sort()不能理解,觉得这样最终只会造成返回return,永远都没办法运行merge(a,from,mid,to),自己陷入了思维的误区,希望哪位高手指点下.
虚心求教!