Page 1 of 1

Problem About Priority Queue STL !!!!

Posted: Wed Nov 16, 2005 5:01 pm
by Chok
Hi all,
I want to know how can i use priority_queue STL when the top element will be the maximum value. Default constructor are increasing order, thats why when i modified them then i got compile error. Please help me. Thanks in advance.

Posted: Wed Nov 16, 2005 5:52 pm
by misof

Code: Select all

priority_queue<myClass, vector<myClass>, greater<myClass> > myQueue

Posted: Wed Nov 16, 2005 9:14 pm
by Chok
Hi misof,
Thankx for ur reply. But one question again, what is the type of myClass ? vector<int>myClass ??

Posted: Wed Nov 16, 2005 10:19 pm
by Krzysztof Duleba
LOL! Which key is the "any key"?

Posted: Wed Nov 16, 2005 11:22 pm
by misof
Chok wrote:Hi misof,
Thankx for ur reply. But one question again, what is the type of myClass ? vector<int>myClass ??
(Sigh.)

myClass is an arbitrary class such that the instances can be compared using the < operator. Any of the default types will work.

Code: Select all

priority_queue<int, vector<int>, greater<int> > Q;
Q.push(6);
Q.push(2);
Q.push(145);
cout << Q.top() << endl;