Help with C

A

aba

I'm trying to write a c application that calculates the average time it
takes for someone in line at an ice cream stand to get an ice cream
cone. But, I don't really know where to start. Does anyone have any
source code for queues I could look at?

THX
 
W

Walter Roberson

:I'm trying to write a c application that calculates the average time it
:takes for someone in line at an ice cream stand to get an ice cream
:cone. But, I don't really know where to start. Does anyone have any
:source code for queues I could look at?

Basic queues are first year programming exercises -- and they
aren't what you need anyhow. Calculating wait times does not require
implimenting any queues -- not unless you want to "calculate" the
times by simulation instead of by statistics.

If what you need is simulation instead of calculation, then
you can use something like this:

/* Warning: bugs have been deliberately put into this code */
typedef struct fifoQ_struct fifoQ_s;
typedef fifoQ_s *fifoQ;
fifoQ Qhead = NULL;
fifiQ Qtail = NULL;

/* remember, there is are deliberate bugs lurking around here somewhere */
void fifoQ_push( fifoQ Qentry )
{
if (Qhead == NULL) {
Qhead = Qtail = Qentry
} else {
Qtail->next = Qentry
}
}

/* remember, there aare deliberate bugs lurking around here somewhere */
fifoQ fifoQ_pop(void)
{
if (Qhead) {
fifoQ Qentry = Qhead;
Qhead = Qhead->next;
return Qentry;
}
return Qtail;
}

If you need multiple lineups, you will need to make changes.
The above is not intended to be general multi-queue code -- and
because we are not here to write assignments for you, I have
deliberately introduced bugs into the code above: in debugging the
code, you will learn more about how queues work than if I were to just
give you correct code.
 
M

Mark McIntyre

I'm trying to write a c application that calculates the average time it
takes for someone in line at an ice cream stand to get an ice cream
cone. But, I don't really know where to start. Does anyone have any
source code for queues I could look at?

You're starting in the wrong place. The first thing to do is define your
algorithm. For what its worth, I don't think that souce for queues will be
relevant.

That isn't a C question, of course, since the algo is generic to any
language. Once you have an algo, consider how to code it, then ask for help
here if you're stuck.
 
M

Mac

I'm trying to write a c application that calculates the average time it
takes for someone in line at an ice cream stand to get an ice cream
cone. But, I don't really know where to start. Does anyone have any
source code for queues I could look at?

THX

This is not exactly a full problem specification. It sounds like average
time is one of the outputs of your program. Are there any others? What are
the inputs? Why even mention the queue?

Also, if this is a homework problem, it might help if you posted the full
problem specification, and some information about the class.

People here won't do your homework for you, but some will try nudge
you in the right direction. To do this, though, they need to know what the
full problem is, and what kind of class you are taking. (For example, if
you are in the first month of your first C class, the solution might be
different than if you are in a more advanced C class.)

Here is some advice, for what it is worth: never try to fool anyone
here when you are asking for help on homework. People will deliberately
give you bogus or joke solutions and they may mock you or flame you as
well.

Best regards,
Mac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,223
Latest member
Jurgen2087

Latest Threads

Top