#include<stdio.h>
#include<stdlib.h>
struct list{
int data;
list *next;
};
int main4(){
list *headA,*headB,*headC,*temp,*p;
temp=(list*)malloc(sizeof(list));
temp->next=NULL;
headA=(list*)malloc(sizeof(list));
headA->next=temp;
p=(list*)malloc(sizeof(list));
p->next=NULL;
while(~scanf("%d",&temp->data)){
temp->next=p;
temp=p;
p=(list*)malloc(sizeof(list));
p->next=NULL;
}
temp=(list*)malloc(sizeof(list));
temp->next=NULL;
headB=(list*)malloc(sizeof(list));
headB->next=temp;
while(~scanf("%d",&temp->data)){
temp->next=p;
temp=p;
p=(list*)malloc(sizeof(list));
p->next=NULL;
}
temp=(list*)malloc(sizeof(list));
temp->next=NULL;
headC=(list*)malloc(sizeof(list));
headC->next=temp;
while(~scanf("%d",&temp->data)){
temp->next=p;
temp=p;
p=(list*)malloc(sizeof(list));
p->next=NULL;
}
temp=headA->next;
list *tempB,*pre;
pre=headA;
tempB=headB->next;
while(temp->next!=NULL){
int er=0;
tempB=headB->next;
while(tempB->next!=NULL){
if(temp->data==tempB->data){
er=1;
break;
}
tempB=tempB->next;
}
if(er==1){
pre->next=temp->next;
temp=temp->next;
} else{
pre=temp;
temp=temp->next;
}
}
temp=headA->next;
list *tempC;
pre=headA;
tempC=headC->next;
while(temp->next!=NULL){
int er=0;
tempC=headC->next;
while(tempC->next!=NULL){
if(temp->data==tempC->data){
er=1;
break;
}
tempC=tempC->next;
}
if(er==1){
pre->next=temp->next;
temp=temp->next;
} else{
pre=temp;
temp=temp->next;
}
}
temp=headA->next;
while(temp->next!=NULL){
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}
A,B,C为递增有序链表,删去A中即在B出现也在C出现的元素
最新推荐文章于 2024-07-24 08:57:17 发布
本文通过C语言实现了一个链表数据结构,并演示了如何从链表中删除与两个不同链表共有元素的全过程。首先创建三个链表,然后遍历第一个链表,检查其元素是否存在于第二个和第三个链表中,如果存在则从第一个链表中删除该元素。最后打印处理后的链表。

830

被折叠的 条评论
为什么被折叠?



