Click here to Skip to main content
14,698,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Stl function that notifies if a vector is contained in another vector but in any order ..
I mean
A{ 1,2,3,4,5,5,6,1}
B{2,1,6} C{5,5,1}
When you compare A and B it should return true bcs it is contained in it in any order..for C it should also be correct because C is conatined in A.(in any order).

One solution : sort them and check via includes( ) ..
Any other than this....

What I have tried:

I have tried one of the way i.e sort and then using includes() ... do the following thing...i mean is it possible in any other way?
Updated 5-Jun-16 21:48pm
Philippe Mori 6-Jun-16 18:07pm
Typically I would use something like a set for the source container and a loop...

1 solution

i mean is it possible in any other way?
Of course it is possible: iterating over the candidate vector (e.g. B) items, check if the item is contained in A. However you have to invalidate the items of A already matched (you could use another vector for the purpose).
shivam gohel 6-Jun-16 10:21am
ya!!! thankyou ..but i am asking that is it possible in any other way compulsory using
STL algorithms....?

SORRY for the incomplete question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900