471,056 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,056 software developers and data experts.

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 3150
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Computer Whizz | last post: by
3 posts views Thread by Amit | last post: by
4 posts views Thread by Dr. J.K. Becker | last post: by
3 posts views Thread by Patrick | last post: by
2 posts views Thread by Dave Taylor | last post: by
5 posts views Thread by madhu | last post: by
1 post views Thread by Rob | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.