Help with C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aba@cus.com

    #1

    Help with C

    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
  • Walter Roberson

    #2
    Re: Help with C

    In article <1110040992.1e5 2c0a3ea5a271df9 54b0ac777f706d@ teranews>,
    <aba@cus.com> wrote:
    :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.
    --
    Studies show that the average reader ignores 106% of all statistics
    they see in .signatures.

    Comment

    • Mark McIntyre

      #3
      Re: Help with C

      On Sat, 05 Mar 2005 11:43:28 -0500, in comp.lang.c , aba@cus.com wrote:
      [color=blue]
      >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?[/color]

      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.
      --
      Mark McIntyre
      CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
      CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

      Comment

      • Ben Pfaff

        #4
        Re: Help with C

        roberson@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
        [color=blue]
        > /* Warning: bugs have been deliberately put into this code */[/color]

        Hey, that's even better than /* this code is untested */. I'll
        remember that :-)
        --
        "When in doubt, treat ``feature'' as a pejorative.
        (Think of a hundred-bladed Swiss army knife.)"
        --Kernighan and Plauger, _Software Tools_

        Comment

        • Mac

          #5
          Re: Help with C

          On Sat, 05 Mar 2005 11:43:28 -0500, aba wrote:
          [color=blue]
          > 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[/color]

          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

          Comment

          Working...