473,320 Members | 1,950 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,320 software developers and data experts.

how to remove duplicate entries in a vector of Pair?

I have a vector of Pair of int:

typedef pair<int, int> MyPair;
typedef vector <MyPair > MyVector

I would like to remove entries if their first are equal, or if their
value is swap ( first of first pair equals to seconds of second pair):

bool equals(MyPair src, MyPair dest ) {
if (( src.first == dest.first) && ( src.second == dest.second))
return true;

if (( src.first == dest.second) && ( src.second == dest.first))
return true;

return false;
}

I think I want to use the 'unique' algorithm and use the above 'equals'
function as the binary predicate.
But before I use the 'unique' algorithm, I need to sort my list. But
for my purpose, I am not sure how to sort my list. base on the 'first'
value? or base on the second value?

Thank you for any pointers.

Mar 25 '06 #1
1 5191
Al************@gmail.com wrote:
I have a vector of Pair of int:

typedef pair<int, int> MyPair;
typedef vector <MyPair > MyVector

I would like to remove entries if their first are equal, or if their
value is swap ( first of first pair equals to seconds of second pair):

What you say above is not equivalent to what you write below, but I'll
assume that what you mean is what you've implemented below.
bool equals(MyPair src, MyPair dest ) {
if (( src.first == dest.first) && ( src.second == dest.second))
return true;

if (( src.first == dest.second) && ( src.second == dest.first))
return true;

return false;
}

I think I want to use the 'unique' algorithm and use the above 'equals'
function as the binary predicate.
But before I use the 'unique' algorithm, I need to sort my list. But
for my purpose, I am not sure how to sort my list. base on the 'first'
value? or base on the second value?


Sort by the smaller of the two pair elements, resolving ties by the
larger of the two pair elements.

Mark
Mar 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: John Black | last post by:
Hi, I am not familiar with for_each very well, suppoase I have a vector<pair<unsigned int, unsigned int> > vec1 and the contents are {<0x00000000, 0x000000FF>, <0x10000000, 0x2FFFFFFF>} what...
11
by: koperenkogel | last post by:
Dear cpp-ians, I am working with a vector of structures. vector <meta_segment> meta_segm (2421500); and the structure look like: struct meta_segment { float id; float num;
9
by: John | last post by:
How do I copy all the elements of a map to a vector efficiently? The vector is empty initially and needs to be populated with the map elements in sorted order. Thanks, --j
5
by: ma740988 | last post by:
For starters, Happy New Year to all!! I created a vector of pairs where pair first is a primitive and pair second is a vector of ints. So now: # include <iostream> # include <vector>
14
by: BarrySDCA | last post by:
I have a database being populated by hits to a program on a server. The problem is each client connection may require a few hits in a 1-2 second time frame. This is resulting in multiple database...
7
by: Allerdyce.John | last post by:
How can I emove an item in STL iterator without use the STL algorithm? I know we can use stl erase, find_if to remove items from a STL vector , but how can I do the same without using STL...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
13
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------------- #include <iostream> #include <string> #include <vector> struct Pair { std::string name;
4
by: ejack | last post by:
int total = static_cast<int>(vComp.size()) - 1; int tTotalUnits = 0; float tTotalCostJob = 0; int i = 0; int j = 0; int counter = 0; bool foundFlag; vector<string> vItems;...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.