Comparing 2 sorted vectors

S

Suma

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
 
J

John Harrison

Suma said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top