これは私のマージソート関数です。VC++Express2010で常に「ベクトル添え字が範囲外」エラーになる理由がわかりません。
vector<int> Ordinatore::doMerge(vector<int> &v1, vector<int> &v2) {
int dimV1 = v1.size();
int dimV2 = v2.size();
int dimTotale = dimV1 + dimV2;
vector<int> merged;
int lh, rh;
lh=0;rh=0;
while(lh < dimV1) {
if (rh < dimV2 && v1[lh] <= v2[rh]) {
merged.push_back(v1[lh]);
lh++;
/* the trouble should start here as far as I've seen with cout & debugging */
while (rh < dimV2 && v2[rh] <= v1[lh]) {
merged.push_back(v2[rh]);
rh++;
}
}
else {
while (rh < dimV2 && v2[rh] <= v1[lh]) {
merged.push_back(v2[rh]);
rh++;
}
merged.push_back(v1[lh]);
lh++;
}
}
return merged;
}