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!