473,240 Members | 1,650 Online

# merging 2 vectors

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.

Jul 23 '08 #1
2 3368
On Jul 23, 4:17 am, "joeme" <jo...@iamnotathome.org.invalidwrote:
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 23 '08 #2
On Jul 23, 4:02*am, James Kanze <james.ka...@gmail.comwrote:
On Jul 23, 4:17 am, "joeme" <jo...@iamnotathome.org.invalidwrote:
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.)
By "dupes" the OP presumably means "duplicates".

--
Marcus Kwok
Jul 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.