Please Help with Printing and Lines for Queues using Linked Lists

This is a discussion on Please Help with Printing and Lines for Queues using Linked Lists within the C Programming forums, part of the General Programming Boards category; Hi, I need to have 3 lines and I need help with them please. This is example of the output: ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    25

    Please Help with Printing and Lines for Queues using Linked Lists

    Hi, I need to have 3 lines and I need help with them please.

    This is example of the output:
    1:00:11pm: Customer ANGEL checking in line A.
    1:01:36pm: Customer ANGEL checking out of line 1 waited 85 seconds.

    so TIME: Customer NAME checking in line x.

    Should I make 3 queue pointers like this?:

    Code:
    struct queue* LineA;
    struct queue* LineB;
    struct queue* LineC;
    
    LineA = (struct queue*)malloc(sizeof(struct queue));
    LineB = (struct queue*)malloc(sizeof(struct queue));
    LineC = (struct queue*)malloc(sizeof(struct queue));
    or only have one pointer and have 3 lines some other way with a function?

    Because I was having trouble with how to print it. If I make a function called lines, I was thinking I could print in main something like this:
    //printf("TIME: Customer %s checking in line %s\n", name, lines(QueuePtr));
    and I would be using if statements in the function or in main
    I haven't sorted out how to do the time yet.
    like How would I get it to say checking in line A?

    So if I do make a function called lines, should it have only one parameter or 3 for each of the lines?

    ex.
    Code:
    int lines(struct queue* p)
    {
        for(i=0; i<=MAX_CUSTOMERS; i++);
        {
            if(items<=10 && p!=NULL)
                p == A;
                return A;
           else if ...
         } 
    };

    //MAX_CUSTOMERS is 8

    These are the functions I have right now:

    //I have them, but I just declared them here.
    void initial_queue(struct queue* p);
    int enqueue(struct queue* p, int value);
    int dequeue(struct queue* p);
    int empty(struct queue* p);
    int front(struct queue* p);


    There is an input file by the way.
    Last edited by Hikaru90; 03-14-2010 at 06:18 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I would use an array queue, but that's just me. 100 rows, and a struct to handle each persons data, and keep it all together: time in, name, line #, etc.

    For a linked list, you want to just add a node, for every new customer, each node should have a struct with the various members of that struct, having the time in, name, (perhaps line #), etc.

    Whether one list is best, or 3, depends on how the customers leave. What data are you being given for their leaving? I believe I can make a pretty good case for just a single array or list, but your assignment may specify the need for having three of them.

    Take it step by step: add a new customer to the line (array or list), update a customer leaving a line, making sure data is recorded in both steps as needed, then delete the node or shuffle the array element values, and get ready for another customer to be either added or to leave.

    So the real question is, what are your exact assignment requirements? There is no ONE way to do this type of assignment, otherwise.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    25
    yeah we could use queues with a linked list or array, but I already started with a linked list, and I think that was the preferred way.

    Oh, and I forgot to include this:

    Code:
    #define MAX_CUSTOMERS 8
    #define MAXNAMELEN 30
    
    // Stores node of the linked list.
    struct node {
        int data;
        struct node* next;
    };
    
    // Stores our queue.
    struct queue {
        struct node* front;
        struct node* rear;
    };
    There's 3 lines (1st line is the express 10 items or less) and they can buy items if they're in line by 8pm starting at 1pm. Last checkout is at or before 11:59:59pm. I have to print when checking in and into which line, and when checking out, I have to print, "TIME: NAME checking out of line x waited y secs."
    Time is in H:MM:SSpm format

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Won't you want the struct node to contain the time and name array, and etc. ? That would keep all the data for a customer, in one place.

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    25
    I haven't done anything for the time since I'm not sure how to do it yet, but I put
    char name[MAXNAMELEN+1]; in the main.

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    25
    For the time, it also says the # of secs it takes to checkout of line once at front is
    40+60x(# of items being bought).

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You need to sort out what info is in the input file, and how you want to handle that. Also, you need to handle the time data, in some way. How is your program going to get the starting time, and whether you want to save it in the struct, (I recommend doing that, because it keeps all the data together for the customer).

    You'll need a little function to read the data file, then I'd tackle the queue's themselves, and last, the little bit of logic to set the final checkout time, and print out the output you need for the assignment, and temporarily, whatever else you might need to verify that everything is correct.

    There is no "line shuffling", right? That is, once the customer is in a queue, they will emerge from the queue, in that same order, right?

  8. #8
    Registered User
    Join Date
    Feb 2010
    Posts
    25
    I scanned in what was in the input file, which was # of days and # of customers. Then
    # of secs after 1pm they get in line, their name, and # of items bought on the same line in the file. Time should be done in main right, not in a function right? The starting time is 1pm. I don't think there is line shuffling. It just depends on which line they get to. Line A is the express line.

  9. #9
    Registered User
    Join Date
    Feb 2010
    Posts
    25
    Oh I have another struct now called customer and it has the name and time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Printing Lines to .txt File
    By Programmer3922 in forum C Programming
    Replies: 2
    Last Post: 08-02-2008, 12:45 PM
  3. Replies: 1
    Last Post: 06-07-2006, 09:42 AM
  4. Printing an array in lines of 10.
    By furiousferret in forum C++ Programming
    Replies: 10
    Last Post: 11-16-2004, 06:30 PM
  5. Printing 20 lines at a time
    By csmatheng in forum C Programming
    Replies: 5
    Last Post: 04-30-2002, 04:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21