📄 gather.txt
字号:
#include "string.h"
#include "stdio.h"
typedef struct LNode{
char data;
struct LNode *next;
}LNode,*LinkList;
void ListInsert(LinkList L,char e)
{
LinkList p,q;
q=L->next;
p=(LinkList )malloc(sizeof(LNode));
p->data=e;
p->next=NULL;
if(!q) L->next=p;
else{
while(q->next) q=q->next;
q->next=p;}
}
void sortList(LinkList L){
char e;
LinkList p,q,s;
if(L->next){
p=L->next;
q=p->next;
e=p->data;
s=p;
while(p->next){
while(q){
if(q->data<e)
{e=q->data;
s=q;
q=q->next;}
else
q=q->next;}
s->data=p->data;
p->data=e;
p=p->next;
q=p->next;
s=p;
e=p->data;}
}
}
void Deletethesame(LinkList L){
LinkList p,q;
p=L->next;
while(p->next){
q=p->next;
if(q->data!=p->data)
p=p->next;
else{
p->next=q->next;
free(q);
}
}
}
void print(LinkList L)
{LinkList p;
int i;
p=L->next;
if(!p) printf("\nthe gather is NULL.\n");
while(p){
printf("%c",p->data);
p=p->next;
}
printf("\n");
}
void IntersectionList(LinkList L1,LinkList L2){
LinkList p,q,L3;
char e;
L3=(LinkList )malloc(sizeof(LNode));
L3->next=NULL;
p=L1->next;
q=L2->next;
if(p||q){
while(p){
e=p->data;
while(q){
if(q->data==e){
ListInsert(L3,e);
q=q->next;}
else
q=q->next;
}
q=L2->next;
p=p->next;
}
}
printf("\nL1:");
print(L1);
printf("\nL2:");
print(L2);
printf("\nthe answer is: ");
print(L3);
}
void DifferenceList(LinkList L1,LinkList L2){
LinkList p,q,L;
L=(LinkList )malloc(sizeof(LNode));
L->next=NULL;
p=L1->next;
q=L2->next;
if(!q)
while(p){
ListInsert(L,p->data);
p=p->next;
}
else if(!q)
;
else if(!p&&!q) L->next=NULL;
else{
while(p){
while(q&&q->data!=p->data)
q=q->next;
if(!q)
ListInsert(L,p->data);
p=p->next;
q=L2->next;
}
}
printf("\nL1:");
print(L1);
printf("\nL2:");
print(L2);
printf("\nthe answer is: ");
print(L);
}
void UionList(LinkList L1,LinkList L2){
LinkList p,q,L;
L=(LinkList )malloc(sizeof(LNode));
L->next=NULL;
p=L1->next;
q=L2->next;
if(!p)
while(q){
ListInsert(L,q->data);
q=q->next;
}
else if(!q)
while(p){
ListInsert(L,p->data);
p=p->next;
}
else if(!p&&!q) L->next=NULL;
else{
while(p){
ListInsert(L,p->data);
p=p->next;
}
p=L1->next;
while(q){
while(p&&p->data!=q->data)
p=p->next;
if(!p)
ListInsert(L,q->data);
q=q->next;
p=L->next;
}
}
printf("\nL1:");
print(L1);
printf("\nL2:");
print(L2);
printf("\nthe answer is: ");
print(L);
}
void BuList(LinkList L1){
LinkList p,L;
char e;
L=(LinkList )malloc(sizeof(LNode));
L->next=NULL;
p=L1->next;
for(e='a';e<='z';e++){
while(p&&p->data!=e)
p=p->next;
if(!p)
ListInsert(L,e);
p=L1->next;
}
printf("\nL1:");
print(L1);
printf("\nthe answer is: ");
print(L);
printf("\n");
}
main(){
LinkList L1,L2;
char e;
int i,j;
L1=(LinkList )malloc(sizeof(LNode));
L1->next=NULL;
L2=(LinkList )malloc(sizeof(LNode));
L2->next=NULL;
printf("please enter the first gather.enter 0 for the end.\n");
for(;;){
e=getchar();
if(e=='0')
break;
if('a'<=e<='z')
ListInsert(L1,e);
sortList(L1);
}
sortList(L1);
Deletethesame(L1);
printf("\nplease enter the second gather.enter 0 for the end.\n");
for(;;){
e=getchar();
if(e=='0')
break;
if('a'<=e<='z')
ListInsert(L2,e);
}
sortList(L2);
Deletethesame(L2);
for(;;){
printf("\nthen you can do:\n");
printf("\n1.Intersection\n2.Difference\n3.Uion\n4.fill gather\n0.end\n\n");
printf("please select you serve number:");
scanf("%d",&i);
switch(i){
case 0:break;
case 1:printf("\nyou select 1 is Intersection\n"); IntersectionList(L1,L2);break;
case 2:printf("\nyou select 2 is Difference\n"); DifferenceList(L1,L2);break;
case 3:printf("\nyou select 3 is Uion\n"); UionList(L1,L2);break;
case 4:printf("\nyou select 4 is fill gather.\n");
for(;;){
printf("please select for the fill gather.\n\n1.L1\n2.L2\n0.end\n "); printf("\nnow enter your number: ");
scanf("%d",&j);
if(j==1)
BuList(L1);
else if(j==2)
BuList(L2);
else if(j==0)
break;
else
printf("\nmessage:you enter a wrong number,please enter again.\n\n");}
default:
printf("\nmessage:you enter a wrong number,please enter again.\n\n");
}
if(i==0)
break;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -