I am trying to insert a few pairs of 'int' into a set, these pairs don't have any order; that is, (1,2) = (2,1)
. So simply I do as follows,
typedef pair<int, int> pairs;
set<pairs> Set;
pair <int,int> myPair;
// adding pairs:
myPair=pair<int,int>(0,1);
pathSet.insert(myPair);
myPair=pair<int,int>(0,2);
pathSet.insert(myPair);
myPair=pair<int,int>(1,0);
pathSet.insert(myPair);
So I end up a set like {(0,1), (0,2) , (1,0)}
. I want to have {(0,1), (0,2)}
. How can I avoid duplicate? Is there anyway? Is there any better ADT like std::unordered_set
in terms of efficiency in comparison with 'set'?
Thanks!
Aucun commentaire:
Enregistrer un commentaire