ç¨åºå¦ä¸ï¼ #include<stdio.h>
#include<stdlib.h>
typedef struct LNode//å®ä¹ç»æä½ç±»åæé
{
char data;
struct LNode*next;
}*pointer;
void Inputdata(pointer head)//å®ä¹è¾å
¥éåå½æ°
{
pointer p;
char tmp;
scanf("%c",&tmp);
while(tmp!='\n')
{
p=(pointer)malloc(sizeof(struct LNode));
p->data=tmp;
p->next=head->next;
head->next=p;
scanf("%c",&tmp);
}
}
void Output(pointer head)//å®ä¹è¾åºéåå½æ°
{
pointer p;
p=head->next;
while(p)
{
printf("%c",p->data);
p=p->next;
}
printf("\n");
}
void Add(pointer head1,pointer head2,pointer head3)//å®ä¹éåç并éå½æ°
{
pointer p1,p2,p3;
p1=head1->next;
while(p1)
{
p3=(pointer)malloc(sizeof(struct LNode));
p3->data=p1->data;
p3->next=head3->next;
head3->next=p3;
p1=p1->next;
}
p2=head2->next;
while(p2)
{
p1=head1->next;
while((p1)&&(p1->data!=p2->data))
p1=p1->next;
if (!p1)
{
p3=(pointer)malloc(sizeof(struct LNode));
p3->data=p2->data;
p3->next=head3->next;
head3->next=p3;
}
p2=p2->next;
}
}
void Same(pointer head1,pointer head2,pointer head3)//å®ä¹éåç交éå½æ°
{
pointer p1,p2,p3;
p1=head1->next;
while(p1)
{
p2=head2->next;
while((p2!=NULL)&&(p2->data!=p1->data))
p2=p2->next;
if((p2!=NULL)&&(p2->data==p1->data))
{
p3=(pointer)malloc(sizeof(struct LNode));
p3->data=p1->data;
p3->next=head3->next;
head3->next=p3;
}
p1=p1->next;
}
}
void Sub(pointer head1,pointer head2,pointer head3)//å®ä¹éåçå·®éå½æ°
{
pointer p1,p2,p3;
p1=head1->next;
while(p1)
{
p2=head2->next;
while((p2)&&(p2->data!=p1->data))
p2=p2->next;
if(!p2)
{
p3=(pointer)malloc(sizeof(struct LNode));
p3->data=p1->data;
p3->next=head3->next;
head3->next=p3;
}
p1=p1->next;
}
} void main()//主å½æ°
{
int n,m;
char str;
printf("è¾å
¥æ°æ®,æå车é®ç»æ (第ä¸ä¸ªéåå¿
须大äºç¬¬äºä¸ªéå)\n");
pointer head1,head2,head3;//声æpointeråé
head1=(pointer)malloc(sizeof(struct LNode));
head1->next=NULL;
head2=(pointer)malloc(sizeof(struct LNode));
head2->next=NULL;
head3=(pointer)malloc(sizeof(struct LNode));
head3->next=NULL; printf("请è¾å
¥éå1:\n");
Inputdata(head1);//è°ç¨è¾å
¥éåå½æ°
printf("请è¾å
¥éå2:\n");
Inputdata(head2);//è°ç¨è¾å
¥éåå½æ°
loop:printf("\n请éæ©æ£ç¡®çæä½ç±»å!\n");
printf("1:并é\t2:交é\t3.å·®é\t4.éåº\n请éæ©åºå·\n");
for(m=0;;m++)
{
scanf("%d",&n);
switch(n)
{
case 1:
printf("两éåç并æ¯\n");
Add(head1,head2,head3);//è°ç¨å¹¶éå½æ°
Output(head3);
head3->next=NULL;
break;
case 2:
printf("两éåç交æ¯\n");
Same(head1,head2,head3);//è°ç¨äº¤éå½æ°
Output(head3);
head3->next=NULL;
break;
case 3:
printf("两éåçå·®æ¯\n");
Sub(head1,head2,head3);//è°ç¨å·®éå½æ°
Output(head3);
head3->next=NULL;
break;
case 4:
getchar();
printf("ç¡®å®è¦éåºå?< Y Same N >\n");
str=getchar();
if(78==str||110==str)
goto loop;
if(89==str||121==str)
exit(0);
else
printf("é误çæ令!\n");
goto loop;
break;
default:
printf("é误çæ令!,请éæ°è¾å
¥!\n\n");
goto loop;
break;}
}
} æçé®æåºã
温馨提示:答案为网友推荐,仅供参考