I wrote this function that is supposed to merge two vectors in ascending order without duplicates.The function should return the resulting vector, but when I try to display it nothing happens although the display function works well for other vectors. I also don't get any error so it acts like the resulting vector it's empty.I am trying to learn iterators and this is the first time using them so maybe I have misunderstood the concept. Here is the code:
vector<int> sort(vector<int> &a, vector<int> &b){
vector <int> sorted;
for (vector<int>::iterator it = a.begin(); it != a.end();) {
for (vector<int>::iterator it2 = b.begin(); it2 != b.end();) {
if (*it < *it2){
sorted.push_back( *it);
++it2;
}
else if (*it >*it2){
sorted.push_back(*it2);
++it;
}
else if (*it == *it2){
sorted.push_back(*it);
++it;
++it2;
}
}
}
return sorted;
}
Am I mistakenly using the iterators? Any help is more than appreciated.