# Include <stdio. h>
# Include <stdlib. h>
# Define N 10
Typedef struct student
{
Int num;
Float score;
Struct student * next;
} Stu;
Stu * Create ()
{
Int I;
Stu * P, * head = NULL, * tail = head;
For (I = 0; I <n; I ++)
{
P = (Stu *) malloc (sizeof (Stu ));
Scanf ("% d % F", & P-> num, & P-> score );
P-> next = NULL;
If (p-> num <0)
{
Free (P );
Break;
}
If (Head = NULL)
Head = P;
Else
Tail-> next = P;
Tail = P;
}
Return head;
}
Void output (Stu * P)
{
While (P! = NULL)
{
Printf ("% d \ t %. 2f \ n", p-> num, p-> score );
P = p-> next;
}
}
Stu * del (Stu * a, Stu * B)
{
Stu * head, * P1, * P2;
P1 = P2 = head = A; // point the P1, P2, and head nodes to the head of linked list.
While (B! = NULL)
{
P1 = P2 = head; // Let P1 and P2 always point to the header of the deleted linked list before each loop
While (P1! = NULL)
{
If (B-> num = p1-> num) // if the student ID is the same, delete the node information.
If (p1 = head) // If the header node is deleted, the position of the header node needs to be moved back.
{
Head = p1-> next;
Free (P1 );
P1 = P2 = head;
}
Else // if you delete an intermediate node
{
P2-> next = p1-> next;
Free (P1 );
P1 = P2-> next;
}
Else // if the student ID is different, the P1 and P2 pointers move backward.
{
P2 = p1;
P1 = p1-> next;
}
}
B = B-> next;
}
Return head;
}
Int main (INT argc, char * argv [])
{
Stu * a, * B, * C;
Printf ("\ n enter the information of linked list A. If the student ID is less than zero, end the input: Format (student ID score) \ n ");
A = create ();
Printf ("\ n enter the information of linked list B. If the student ID is less than zero, end the input: Format (student ID score) \ n ");
B = create ();
System ("CLS ");
Printf ("\ n linked list a information: \ n ");
Output ();
Printf ("\ n linked list B information: \ n ");
Output (B );
C = del (A, B );
Printf ("\ n ");
Output (C );
Return 0;
}