C语言结构体一人条问题:求高手检错
从链表1中删去与链表2号码的结构体。#include "stdio.h"
#include "malloc.h"
#define LA 4
#define LB 5
struct student
{
char num[6];
char name[8];
struct student *next;
}A[LA],b[LB];
void print(struct student *head)
{ struct student *p1;
p1=head;
printf("输出数据\n");
while(p1!=NULL)
{printf("%d %s \n",p1->num,p1->name);
p1=p1->next;
}
}
struct student *creat(struct student *head,struct student *head2)
{
struct student *p,*q;
struct student *p2=head2;
int a;
q=p=head;
for(;p!=NULL;p=p->next/*p再后移*/)
{ for(p2=head2;p2!=NULL;p2=p2->next)/*循环比较链表1和2的num*/
{
if(p->num==p2->num) /*若p的num和p2的num相同时*/
{ if(p==head) /*再判断是否为第一个地址*/
{ head=q->next; /*若是,则将head后移一个地址*/
a=1; /*用作结束循环*/
}
else
{q->next=p->next;/*若不是第一个地址,则跳过链表1和2两同num*/
a=1; /*用作结束循环*/
}
}break; /*若执行了if语句则跳出循环*/
if(a==1)break; /*再跳出循环*/
}
q=p; /*让q指向p之前的一个地址*/
}
free(p);
return head;
}
void main()
{
struct student a[LA]={{"101","Wang"},{"102","LI"},{"105","zhang"},{"106","Wei"}};
struct student b[LB]={{"103","Zhang"},{"104","Ma"},{"105","Chen"},{"107","Guo"}, {"108","Lui"}};
struct student *head,*head2;
a[0].next=&a[1];/*连接成链表*/
a[1].next=&a[2];
a[2].next=&a[3];
a[3].next=NULL;
b[0].next=&b[1];
b[1].next=&b[2];
b[2].next=&b[3];
b[3].next=&b[4];
b[4].next=NULL;
head=a;
head2=b;
head=creat(head,head2);
print(head);
getch();
}
拜托了