C - Queue Program Help.

Discussion in 'C' started by johnslater, Feb 18, 2008.

  1. johnslater

    johnslater New Member

    Joined:
    Feb 18, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Good afternoon (or morning). I have been having some C help over the weekend for my college course coursework. I suppose this is my last resort, no offence.

    The assignment says i'm supposed to do some kind of C queue system, very basic type of thing and only needs a few lines of code, however i didnt learn C very well so everything is confusing to me.

    The queue system should do the following

    1.) User enters 1
    2.) 1 is added to a queue
    3.) User enters 2
    4.) 2 is added to the queue
    etc
    5.) As each number is added the queue will look like this... 1: 2: 3: 4: 5: 6: 7:

    6.) User enters 98 (which removes from the queue)
    (NOTE: The first item in the queue (e.g 1) needs to be removed and the index for each other number needs to be changed, so the queue will still look like (2: 3: 4: 5: 6: 7:) but the index for each number will be (2[1]: 3[2]: 4[3]: etc..)

    I have been given the 'test harness' as its being called but the code puzzles me, i guess im much better suited for VB or PHP.

    My code is below, i need to add my code where there is a comment called
    //*********************************
    // HERE
    //*********************************


    -----------------------------------------

    PHP:
    // include the IO stuff
    #include <stdio.h>
    // pre-define the enqueue and dequeue functions
    void enqueue(int x);
    void dequeue(void);
    void list(void);
    // define data variable names
    int aqueue[99];
    int i;
    // define integer constants
    const int MAX 10// just for testing read 90
    const int END 99// what the user types to end run
    const int DQ 98;  // what the user types to remove from queue (dequeue)

    int main()
    {
        
    // define local data variable names
    int imp;
    printf("------------------------------------------- \n");
    printf("Queue Test Harness named QueuesHarness.c    \n");
    printf("------------------------------------------- \n");
    printf("This works Enqueue and Dequeue not yet coded\n");
    printf("Coding Enqueue and Dequeue is your job.\n");
    printf("--------------------------------------------\n");
    printf("Input 99 to end job \n");
    printf("Input 98 to remove from queue \n");
    printf("Input an integer, imp where 0 <= imp < 98 to add to queue \n");
    do
    {
        
    printf("\n======================\n");
        
    printf("\nKey in\n %d to remove from queue,\n %d to end, and \n any other number to add to queue\n",DQEND);
        
    scanf("%d",&imp);                // get the input number
        
    if (imp == DQ)                // DQ = 98 means remove from queue (dequeue)
            
    {
                 
    dequeue();                // do the dequeue
            
    }
        else
            {
                if (
    imp != END)        // END = 99 means end of run
                    
    {
                        
    enqueue(imp);    // do the enqueue
                    
    }
                else
                {
                    
    printf ("Request END \n");
                }
            }
    } while (
    imp != END);
       
    printf("\n*************************\n");
       
    printf("*End of run Queue - BYE *");
       
    printf("\n*************************\n");
       return 
    0;                    // good end returned to operating system
    }
    //
    void enqueue(int x)                 // enqueue code
    {    
    //******************************
    // HERE
    //******************************
        
    printf("==> in enqueue %d\n",x);  // Data sent to enqueue remove this line when all OK
        
    return x;
    }
    //
    void dequeue(void)                    // dequeue code
    {
    //******************************
    // HERE
    //******************************
        
    printf("==> in dequeue\n");      // No Data sent to dequeue remove this line when all OK
    }
    //
    void list()                           // printout the queue
    {
        
    int k=1;
        while (
    <= i)
        {
            
    printf(": %d"aqueue[k]); // put a ': ' between numbers
            
    k++;
        }
    }

    If someone could give me a real shove in the right direction that would be great.

    NOTE: The first one is to add to the queue and the second one is to remove i believe. (when 98 is typed in it removes from the queue)

    If you could keep your help simple that would be great, i'm a complete noob with C, even though this is my second program.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice