std::pair for storing name and val instead of using
struct node by using this you need not define the ‘<’ or ‘>’ operator for
If you want the pair with the smallest value of
val, you need a min priority queue or priority queue in the opposite case.
How to use
std::priority_queue in this case ?
priority_queue< pair< int, string > , vector< pair< int, string> >, greater< pair< int, string > > > pq;
// assuming name is of type std::string
Pushing an element in pq :
cin >> value >> name;
Extracting the minimum value and the name corresponding to that value :
pair< int, string > p = pq.top();
cout << "Minimum value is : " << p.first;
cout << "Name corresponding to " << p.first << " is " << p.second;
For more information about
std::priority_queue refer this.