|
-
December 8th, 2004, 06:57 AM
#1
priority queue
Hi I'm working on a graph assignment for school. I need to implement a priority queue or minheap. I am fairly new to c++. How do you implement a priority que using an abstract data type. For instance I would like to be able to to have an edge * e and a queue q so that I could enque e using its cost value.
Sorry if that didn't make alot of sense:
This won't complie but heres what I'm trying to do:
Code:
edge * e = new edge(string routerOne, string routerTwo, int cost);
priority_queue<* edge>*q;
q.enque(e);
I would like to do this so that edge is cost is used to determine priority
-
December 8th, 2004, 07:28 AM
#2
Re: priority queue
C++ already has a priority_queue class as part of the standard library.
Code:
template <class T, class Container = vector<T>,
class Compare = less<typename Container::value_type> >
class priority_queue;
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|