C++ 归并排序问题?
程序的目的是把两个排序好的向量合并成一个排序的向量。代码如下:
#include <iostream>
#include <vector>
using namespace std;
void Merge(vector<int> &, int, vector<int> &, int);
int main() {
vector<int> A, B;
for(int i = 0; i < 5; i++)
A.push_back(i * 2 + 1);
for(int i = 0; i < 7; i++)
B.push_back(i * 2 +2);
Merge(A, 5, B, 7);
for(vector<int>::iterator p = A.begin(); p != A.end(); p++) */
cout << (*p) << ",";
cout << endl;
return 0;
}
void Merge(vector<int> & A, int m, vector<int> & B, int n) {
vector<int> AA;
for(int i = 0; i < m; i++)
AA.push_back(A[i]);
for(int aa = 0, b = 0, a = 0; aa < m || b < n; ) {
if(aa < m && (AA[a] <= B[b] || b >= n)) A[a++] = AA[aa++];
if(b < n && (B[b] <= AA[a] || a >= m)) A[a++] = B[b++];
}
}
编译报错segmentation default.
请看看是哪儿的问题?