For eg:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <set>
- using namespace std;
- int main ()
- {
- set<int> myset;
- set<int>::key_compare mycomp;
- set<int>::iterator it;
- int i,highest;
- mycomp = myset.key_comp();
- for (i=0; i<=5; i++) myset.insert(i);
- cout << "myset contains:";
- highest=*myset.rbegin();
- it=myset.begin();
- do {
- cout << " " << *it;
- } while ( mycomp(*it++,highest) );
- cout << endl;
- return 0;
- }
I wanted to try the same on a higher-level data straucture such as a structure of type:
Expand|Select|Wrap|Line Numbers
- struct node
- {
- int a,b;
- };
So, how do I use key_comp() and value_comp() to define our own comparison function??