vector<int>& mergesort(vector<int> &a) {
if (a.size() == 1) return a;
int middle = a.size()/2;
vector<int>::const_iterator first = a.begin();
vector<int>::const_iterator mid = a.begin() + (middle - 1);
vector<int>::const_iterator last = a.end();
vector<int> ll(first, mid);
vector<int> rr(mid, last);
vector<int> l = mergesort(ll);
vector<int> r = mergesort(rr);
vector<int> result;
result.reserve(a.size());
int dp = 0, lp = 0, rp = 0;
while (dp < a.size()) {
if (lp == l.size()) {
result[dp] = (r[rp]);
rp++;
} else if (rp == r.size()) {
result[dp] = (l[lp]);
lp++;
} else if (l[lp] < r[rp]) {
result[dp] = (l[lp]);
lp++;
} else {
result[dp] = (r[rp]);
rp++;
}
dp++;
}
a = result;
return a;
}
它正確編譯但在執行中,我得到:問題與++歸併用C
This application has requested the runtime to end it in an unusual way.
這是一個奇怪的錯誤。
是否有什麼是根本上錯誤的代碼?
如果您提到平臺,它可能會有所幫助,但錯誤消息聽起來很像一個剛剛拋出未捕獲異常的Visual C++程序。 – 2010-04-19 19:51:17