Thread: linked lists, stacks and queues

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    9

    linked lists, stacks and queues

    Hello!
    I don't know if you can help me but I've got an assignment that I can't solve.

    Suppose we have 2 ferry boats, S and Q (stack and queue implementation). We have to build a program with the following conditions:
    there's a file to read data (carplates)

    car0.txt
    NBE1016 S<new line>
    XKZ2016 Q<new line>
    IPN1017 S<new line>
    PP21017 Q<new line>
    NNB2018 Q<new line>

    then suppose that at first, ALL cars from dock fill boat S (which ships when boat is full or there's no car left in the dock)

    and travell until the middle dock where ALL cars leave S,and a new file is written with the new order.

    Then, cars for Q fill that boat (which ships when boat is full or there's no car for Q left in the dock) until the final destination.


    We MUST use the following structures:
    Code:
    /* Node structure */
    typedef struct dnode {
        char *Name; /* CAR ID */
        struct dnode *Next; /* Pointer to next node in the linked-list */
    } DNODE;
    
    /* Stack structure type */
    typedef struct Stack {
        int Capacity; /* the max elements stack is permitted to hold */
        int NumElements; /* current number of elements in stack */
        DNODE *Top; /* pointer to top node */
    } STACK;
    
    /* Queue structure type */
    typedef struct Queue {
        int Capacity; /* the max elements in queue */
        int NumElements; /* num of elements in queue */
        DNODE *First; /* pointer to first node */
        DNODE *Last;  /* pointer to last node */
    } QUEUE;

    We run the program with the following arguments:
    ./as.exe <capacity of S> <capacity of Q> cars0.txt out0_s out0_q

    eg
    ./as.exe 2 1 cars0.txt out0_s out0_q

    and the output must be
    out0_s0.txt
    XKZ2016<new line>
    NBE1016<new line>

    out0_q0.txt
    XKZ2016<new line>

    out0_q1.txt
    NBE1016<new line>

    out0_s1.txt
    PP21017<new line>
    IPN1017<new line>

    out0_q2.txt
    PP21017<new line>

    out0_q3.txt
    IPN1017<new line>

    out0_s2.txt
    NNB2018<new line>

    out0_q4.txt
    NNB2018<new line>

    BUT I MESSED UP everything ....

    I attach my code so far.................

    Can anyone help me PLEASE PLEASE PLEASE!
    Thanks!

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    IMHO figure out the difference between C source and header files.
    Are you sure that stack.h and queue.h are indeed headers or do they need to be source files?

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    9
    Yes, that's how we've been told to build them...
    So, we must follow the rules!

    Thanks.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by aniramg69
    BUT I MESSED UP everything ....
    How does it not work? If you really did mess up everything, then restart from scratch, but this time do one part, test, and then do another part, test, etc.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    I would heed laserlight and start from scratch as the whole thing is messed up.
    This time take care to separate the statements that should go into the source file (as3b.c)
    from the ones that should go into the header files (stack.h and queue.h).

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    1
    Did u find the solution finally? i have the same problem in my exercise.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    For the sake of everyone could you post the problem. It's not completely clear to me what the OP has in mind.

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    9
    I've made some improvements to the code
    BUT the result is not what I want...

    here it is

    I'd appreciate some real help...
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stacks and queues info
    By Emeighty in forum C++ Programming
    Replies: 4
    Last Post: 11-02-2008, 01:41 AM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. need help understanding Linked lists
    By Brain Cell in forum C Programming
    Replies: 6
    Last Post: 07-16-2004, 01:29 PM
  4. stacks and queues
    By j0hnb in forum C Programming
    Replies: 4
    Last Post: 04-16-2003, 09:44 PM
  5. using Stacks & Queues to compare Strings
    By eskimo083 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2003, 05:03 PM