473,240 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,240 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 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.

Similar topics

5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
5
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
4
by: Dr. J.K. Becker | last post by:
Hi all, I have vectors that holds pointers to other vectors, like so: vector<whatever> x; vector<whatever*> z; z=&x; Now I add something to x
3
by: Patrick | last post by:
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best,...
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
2
by: Dave Taylor | last post by:
Is there a decent explanation of how menu merging with MDI forms work in VB.NET? I've read through the online help and it still seems that whenever I change menus around or whatever, it breaks...
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.