c++ - Merging vectors -


i wrote function supposed merge 2 vectors in ascending order without duplicates.the function should return resulting vector, when try display nothing happens although display function works other vectors. don't error acts resulting vector it's empty.i trying learn iterators , first time using them maybe have misunderstood concept. here code:

      vector<int> sort(vector<int> &a, vector<int> &b){          vector <int> sorted;            (vector<int>::iterator = a.begin(); != a.end();) {           (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 mistakenly using iterators? more appreciated.

std::set_union defined in <algorithm> want. see here reference. under "possible implementation" can find working implementation.


Comments

Popular posts from this blog

What can cause "Required Package 'IndyCore' not found" when compiling a Delphi 2010 project? -

Change the color of an oval at click in Java AWT -