#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
typedef struct Student
{
int num;
char name[MAXSIZE];
struct Student *next;
}Student;
int n;
Student* CreateLink(Student *P)
{
Student *P1,*head;
n=0;
P=P1=(Student *)malloc(sizeof(Student));
head=NULL;
printf("input Number:");
scanf("%d",&P->num);
getchar();
if(P->num != 0)
{
printf("input Name:");
scanf("%s",P->name);
getchar();
}
while(P->num != 0)
{
n++;
if(n==1)
{
head=P;
}
else
{
P1->next=P;
}
P1=P;
P=(Student *)malloc(sizeof(Student));
printf("input Number:");
scanf("%d",&P->num);
getchar();
if(P->num != 0)
{
printf("input Name:");
scanf("%s",P->name);
getchar();
}
}
P1->next=NULL;
return (head);
}
Student* Del(Student *A,Student *B)
{
Student *head,*P;
head=A;
//for(;B != NULL;B->next);
for(;B != NULL; B = B->next)
{
while(A)
{
if(A->num == B->num)
{
if(A==head)
head=A->next;
else
{
P->next=A->next;
A=A->next;
}
}
else
{
P=A;
A=A->next;
}
}
}
return (head);
}
void print(Student *P)
{
Student *head;
head=P;
while(head!= NULL)
{
printf("No. %d Name: %s\n",head->num,head->name);
head=head->next;
}
}
int main()
{
Student A,B;
CreateLink(&A);
printf("The Graph A is:\n");
print(&A);
CreateLink(&B);
printf("The Graph B is:\n");
print(&B);
Del(&A,&B);
printf("The New Graph A is:\n");
print(&A);
return 0;
}
|