merging 2 vectors

J

joeme

How would one using STL do the following tasks:

1) merge 2 sorted vectors with dupes, result shall be sorted

2) merge 2 sorted vectors without dupes, result shall be sorted

3) merge 2 unsorted vectors with dupes, result does not need to be sorted

4) merge 2 unsorted vectors without dupes, result does not need to be sorted

By "merge" I mean inserting the second vector to the first vector.
 
J

James Kanze

How would one using STL do the following tasks:
1) merge 2 sorted vectors with dupes, result shall be sorted
2) merge 2 sorted vectors without dupes, result shall be sorted
3) merge 2 unsorted vectors with dupes, result does not need to be sorted
4) merge 2 unsorted vectors without dupes, result does not need to be sorted
By "merge" I mean inserting the second vector to the first vector.

And by dupes? (The only meaning of dupe that I know is a person
who is easily taken in by a scam, and the dictionaries I have
access to seem to agree. But that doesn't seem to fit here.)

Anyway, for the sorted vectors, there's std::merge, in the
algorithms, and for the unsorted, You'd probably have to insert
one, then the other, into an empty vector (or copy one to create
a new vector, then insert the other); you could also consider
some special sort of iterator which visits both vectors, and use
the two iterator constructor of vector, but IMHO, that would
only be justified if you needed that sort of special iterator
for other things as well.
 
M

Marcus Kwok

And by dupes?  (The only meaning of dupe that I know is a person
who is easily taken in by a scam, and the dictionaries I have
access to seem to agree.  But that doesn't seem to fit here.)

By "dupes" the OP presumably means "duplicates".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top