Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. priority queue with time limit

priority queue with time limit

Scheduled Pinned Locked Moved ATL / WTL / STL
helpc++dockerdata-structures
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    charian0920
    wrote on last edited by
    #1

    hi c++ guru. i need your help... i'm new in hardcore c++ and currently working on a c++ container namely the priority_queue. i don't have problem using the priority_queue itself but i have this additional requirement to also consider the age of the items in the queue. my current implementation only deals with the priority of the items in the queue by overloading the "<" operator. i don't know yet what to do when considering the age of the items in the priority_queue. any help is greatly appreciated... PS: sample code would be a great help... charian

    P M 2 Replies Last reply
    0
    • C charian0920

      hi c++ guru. i need your help... i'm new in hardcore c++ and currently working on a c++ container namely the priority_queue. i don't have problem using the priority_queue itself but i have this additional requirement to also consider the age of the items in the queue. my current implementation only deals with the priority of the items in the queue by overloading the "<" operator. i don't know yet what to do when considering the age of the items in the priority_queue. any help is greatly appreciated... PS: sample code would be a great help... charian

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      Try googling...

      1 Reply Last reply
      0
      • C charian0920

        hi c++ guru. i need your help... i'm new in hardcore c++ and currently working on a c++ container namely the priority_queue. i don't have problem using the priority_queue itself but i have this additional requirement to also consider the age of the items in the queue. my current implementation only deals with the priority of the items in the queue by overloading the "<" operator. i don't know yet what to do when considering the age of the items in the priority_queue. any help is greatly appreciated... PS: sample code would be a great help... charian

        M Offline
        M Offline
        Michael Sadlon
        wrote on last edited by
        #3

        You can make another priority_queue that stores the priority as the time you added the item to the priority_queue. Store a pointer to the same item in both queues? Of course, this is kind of an ugly way of doing it. I recently made a priority_queue that stores pointers to Event objects. Each Event stores the time the event should run, as well as other important information it needs when it runs. I overloaded operator() and operator< to handle comparing the Event->_nTime to another Event->_nTime. Basically I pop the next Event to run (smallest time) and run it when it's time has come. Unfortunately, i don't think that approach will help you. Sounds to me like you want to extend the priority_queue itself to track age of items as well as priorities, which is pretty difficult. Easiest method might be to use two of them like I mentioned above. Maybe some more details on what your program does?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups