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
    Location
    Kolkata@India
    Posts
    2,498
    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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,712
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,712
    As in you just want help in implementing a min heap? If so, what have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,304
    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