CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: priority queue

  1. #1
    Join Date
    Dec 2004
    Posts
    4

    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

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    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
  •  





Click Here to Expand Forum to Full Width

Featured