Problem About Priority Queue STL !!!!

Post here if you don't find any other place for your post. But please, stay on-topic: algorithms, programming or something related to this web site and its services.

Moderator: Board moderators

Post Reply
Chok
New poster
Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

Problem About Priority Queue STL !!!!

Post by Chok » Wed Nov 16, 2005 5:01 pm

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.

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof » Wed Nov 16, 2005 5:52 pm

Code: Select all

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

Chok
New poster
Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

Post by Chok » Wed Nov 16, 2005 9:14 pm

Hi misof,
Thankx for ur reply. But one question again, what is the type of myClass ? vector<int>myClass ??

User avatar
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba » Wed Nov 16, 2005 10:19 pm

LOL! Which key is the "any key"?

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof » Wed Nov 16, 2005 11:22 pm

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;

Post Reply

Return to “Other words”