If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > C++ stl priority_queue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-12-02, 06:48
hakwes hakwes is offline
Registered User
 
Join Date: Mar 2002
Posts: 14
Question C++ stl priority_queue

Hi,
I want to use the stl priority_queue to store "Task's" sorted by the Task's priority. When I create a Task and put it in the queue I would like to be able to change the priority of the created task and thereafter I would like to sort the queue again.

struct Task
{
int priority;
friend bool operator < (const Task& t1, const Task& t2);
Task(int p=0) : priority(p) {}
};

bool operator < (const Task& t1, const Task& t2)
{
return t1.priority < t2.priority;
}

int main()
{
priority_queue<Task> scheduler;
Task a,b,c;
a.priority = 2;
scheduler.push(a);
scheduler.push(b);
scheduler.push(c);
a.priority = 0; // This Obviously dous not work but that
// is no suprise. How do I get to work?

while(!scheduler.empty())
{
cout << scheduler.top().priority << "\n";
scheduler.pop();
}
return 0;
}
Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On