Google Answers Logo
View Question
Q: help with priority queues ( Answered 5 out of 5 stars,   0 Comments )
Subject: help with priority queues
Category: Computers > Programming
Asked by: balzack-ga
List Price: $12.00
Posted: 03 May 2003 23:37 PDT
Expires: 02 Jun 2003 23:37 PDT
Question ID: 199123
hello all-

i need some help implementing a priority queue which works by using
min heaps for storing the data. appropriate stuff it should have is
adding an event to the queue, creating an empty one, getting and
removing the even with lowest eta, and seeing if it is empty.

it should also contain something similar to a struct like this one: 
struct item { event, eta } 

it doesn't have to be anything extremely fancy, just a good
implementation of it. if you have any questions please feel free to
ask. thanks alot for the help

Request for Question Clarification by mathtalk-ga on 04 May 2003 06:37 PDT
Hi, balzack-ga:

You don't explicitly state what programming language you are
interested in, but from the mention of struct's, I assume it's in the
C-family of languages.

The C++ Standard Library (STL) provides a template class:


in the same header file as ordinary queues.  Please clarify whether
the STL approach interests you, and any additional "design" issues.

regards, mathtalk

Request for Question Clarification by dogbite-ga on 04 May 2003 13:03 PDT
Hey balzack-ga,

  If you're not interested in using templates
  and simply want somebody to write you a 
  priority queue for event structures, I'm
  willing to do that.


Clarification of Question by balzack-ga on 04 May 2003 14:09 PDT

First off, i am talking in C++ preferrably, otherwise C is ok.

I do not want to use templates, just a simple event structure using
priority queues like in the intial post is what i'm looking for. just
like dogbite suggested. also i liked dogbite's previous help with one
of my questions alot so dogbite, if you want to answer it, i'd be glad
to see that.

Subject: Re: help with priority queues
Answered By: dogbite-ga on 04 May 2003 19:57 PDT
Rated:5 out of 5 stars
Hi balzack-ga,

  I have put the code for your priority 
  queue here:

  The instructions for how to compile
  and run it are in the top of the file.

  Please let me know if it works for you.


Request for Answer Clarification by balzack-ga on 05 May 2003 15:02 PDT
Hi there-

I have a few questions.

1) What arguments are supposed to be passed to the program via the
command line? Or is that a mistake?

2) After I run the program, it works fine but at the end, after it
correctly prints out the testing code, it gives me an error message.
Do you have any idea what this could be from? Not a compiler error, it
happens when I am running the program.

3) Just want to make sure, when using heaps its easier not to include
[0], that is what is going on, correct?

Thanks for the help!

Clarification of Answer by dogbite-ga on 05 May 2003 15:08 PDT
Hi balzack-ga,

  I'll take the questions in order:

1) There are no command line arguments for
   the program.  Your question didn't specify
   that it took any arguments.  Are you asking
   why the main() function has int argc and
   char *argv[] in the function declaration?
   If so, that's just standard form, even when
   there are no command-line arguments.

2) What error are you receiving?  I'm guessing that
   is because the priority queue is empty for the
   last cout.  It printed (null) on my system, but
   maybe it breaks on yours.  I have updated the
   priorityqueue.tar.gz file -- hopefully you won't 
   get an error now.

3) Yes, I ignore the zeroth element in the array because
   it makes the math easier.  You're correct.

   I hope that helps.


Request for Answer Clarification by balzack-ga on 05 May 2003 15:55 PDT
OK, I just usually use a void main(void) if there aren't any

It works fine now, you're right, it was trying to print an empty
holder and it caused the error.

Great job, thanks alot for the help.

Clarification of Answer by dogbite-ga on 05 May 2003 16:00 PDT
Hey balzack-ga,

  I'm very happy that I could help.

  Let me know if you need me to
  answer something else in the future.

  And, thanks for the tip!

balzack-ga rated this answer:5 out of 5 stars and gave an additional tip of: $2.00
dogbite, you've done it again! thanks for the great work and quick
responses! I really appreciate the help!

There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy