you must do the following: class vertex { public: vertex *parent; int value; vertex() { parent = NULL; value = rand(); } ~vertex(); }Array[10];
bool operator < (const vertex& v1, const vertex& v2) { return (v1.value > v2.value); } void main() { //create a priority_queue priority_queue<vertex,vector<vertex>,less<vector<vertex>::value_type> > Q; //now can insert your elements of type vertex in pq for(i=0;i<9;++i) Q.push(Array[i]); //now Q.top() will give the minimum value cout<<Q.top().value; } On Sat, Jun 14, 2008 at 3:40 PM, Pratyush <[EMAIL PROTECTED]> wrote: > > I want to construct a min priority queue to hold class objects > eg > class vertex > { > public: > vertex *parent; > int value; > vertex() > { > parent = NULL; > value = rand(); > } > ~vertex(); > }array[10]; > > priority_queue<vertex> Q; > for(i=0;i<9;++i)Q.push(array[i]); > > the min-heap is to be ordered by the "value" and Q.top() should return > the vertex with min value ( like we require in prim's algorithm). > Can anybody assist me how to create the priority_queue using STL in C+ > + and how is the comparator class and container is to be written for > this. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---