Like Tree1Likes
  • 1 Post By laserlight

C++ stl

This is a discussion on C++ stl within the C++ Programming forums, part of the General Programming Boards category; I want to implement priority queue using STL. Basically I want to use it for storing states(array of size k) ...

  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278

    C++ stl

    I want to implement priority queue using STL.
    Basically I want to use it for storing states(array of size k) sorted according cost.
    Which standard template is useful for me?

    I want to implement Insert, GetMin(based on cost), Isempty operations on the priority queue.
    Any help syntax would also be very helpful.

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Posts
    2,598
    Quote Originally Posted by anirban View Post
    I want to implement priority queue using STL.
    Basically I want to use it for storing states(array of size k) sorted according cost.
    Which standard template is useful for me?

    I want to implement Insert, GetMin(based on cost), Isempty operations on the priority queue.
    Any help syntax would also be very helpful.
    Just wrap a std::set in your class, providing the right comparator functions.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,794
    Quote Originally Posted by anirban
    I want to implement priority queue using STL.
    Basically I want to use it for storing states(array of size k) sorted according cost.
    Which standard template is useful for me?
    You can use the std::priority_queue container adapter.

    By default, it uses heap operations like std::make_heap, std::push_heap and std::pop_heap on an internal std::vector.
    iMalc likes this.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278
    Any syntax help for implementing min heap please?
    I am new to this and need to know the syntax.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,794
    As in you just want help in implementing a min heap? If so, what have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,313
    The 4th and 5th links here look like they would be very useful to you:
    Let me google that for you
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21