By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,500 Members | 1,769 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,500 IT Pros & Developers. It's quick & easy.

Comparing 2 sorted vectors

P: n/a
This is more or less a follow up of the previous question I posed yday
:)
I have vectors V1 and V2 and a functor (less_than) for sorting the
vectors.
The vectors hold object pointers (CPerson*,and not objects).
struct Less
{
bool operator()(const CPerson* x, const CPerson* y) const
{
..
}

}
I call sort(V1.begin(),V1.end(),Less()) and sort works OK.No issues
here
I can also sort V2 similiarly
Now I want to compare V1 and V2 - both are now sorted -
What is the best way to do this-given that I already have the logic to
compare individual elements in the vector encoded in the functor?
Of course I can iterate over the elements of V1 and V2 and call a
function that encapsulates the functor logic to compare elements (and
call thatin the functor)
Any inputs will be useful

Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Suma wrote:
This is more or less a follow up of the previous question I posed yday
:)
I have vectors V1 and V2 and a functor (less_than) for sorting the
vectors.
The vectors hold object pointers (CPerson*,and not objects).
struct Less
{
bool operator()(const CPerson* x, const CPerson* y) const
{
..
}

}
I call sort(V1.begin(),V1.end(),Less()) and sort works OK.No issues
here
I can also sort V2 similiarly
Now I want to compare V1 and V2 - both are now sorted -
What is the best way to do this-given that I already have the logic to
compare individual elements in the vector encoded in the functor?
Of course I can iterate over the elements of V1 and V2 and call a
function that encapsulates the functor logic to compare elements (and
call thatin the functor)
Any inputs will be useful


std::lexicographical_compare(V1.begin() V1.end(), V2.begin(), V2.end(),
Less());

john
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.