Here is the problem.
The input is 4 kinds of command,
"ADD S C" which means add student S into course C.
"DROP S C" means drop student S into course C.
"PRINTS S" mean print out all the course that student S taken.
"PRINT C" mean print out all the student taken course C.
The input will stop until its reach end of file(EOF).
So, I decided to use a linked list to do this.
first, I define a struct
typedef struct node
{
int SID;
int CID;
struct node* next;
}node;
Then, i make a create_node function.
node* create_node(int IDS, int IDC)
{
node* copy = (node*)malloc(sizeof(node));
copy->SID = IDS;
copy->CID = IDC;
copy->next = NULL;
return copy;
}
And, i also make a insert node function.
void insert_node(node* a, node* b)
{
a->next = b;
b->next = NULL;
}
The problem come out. Because the input would only stop when its reach End Of File. That means there may be "ADD 1 2", "ADD 2, 3" ....... appear so many times. I want to know how to link up two node, because in usually, I will
node* a = create_node(2, 3);
node* b = create_node(7, 7);
insert_node(a, b);
but now, I cannot do this. Can anyone give me an example? Thanks a lot.