I have two functions that I am using to attempt to perform a merge sort. Unfortunately, it claims that my call to merge does not match any existing function definitions- which has me dumbfounded since it appears to match perfectly.
// Merge Sort:
vector<int> MergeSort(vector<int> &x) {
int n = x.size();
if (n <= 1) {
return x;
}
size_t const half = x.size() / 2;
vector<int> u(x.begin(), x.begin() + half);
vector<int> v(x.begin() + half, x.end());
vector<int> i = MergeSort(u);
vector<int> j = MergeSort(v);
vector<int> m = merge(i, j); // no matching function for call to 'merge'
return m;
}
// Merge vector
vector<int> merge(vector<int> &x, vector<int> &y) {
vector<int> t;
while (!x.empty() || !y.empty()) {
if (x.back() > y.back()) {
t.push_back(y.back());
y.pop_back();
} else {
t.push_back(x.back());
x.pop_back();
}
if (!x.empty()) {
t.push_back(x.back());
x.pop_back();
} else {
t.push_back(y.back());
y.pop_back();
}
}
return t;
}
I have tried a bunch of silly things like changing the order of definitions and even testing this with different variable types but run into the same issue despite my efforts.
I've been messing with this for over an hour now and am completely stuck. I seriously hope I am not overlooking something obvious. Any help would be greatly appreciated!