3、);s=(LinkList*)malloc(sizeof(LinkList));s->data=num;r->next=s;//鏈接到表中r=s;//r指向新的尾結(jié)點(diǎn)}r->next=NULL;returnhead;}LinkList*merge(LinkList*L1,LinkList*L2){LinkList*L3,*pa,*pb1,*pb2,*pc;L3=(LinkList*)malloc(sizeof(LinkList));//申請(qǐng)結(jié)點(diǎn)L3->next=NULL;//初始化鏈表L3pa=L1->next;//pa是鏈表L1的工作指針,指向第一個(gè)
4、結(jié)點(diǎn)pb1=pb2=L2->next;//pb1是鏈表L2的工作指針,指向第一個(gè)結(jié)點(diǎn)pc=L3;//pc是鏈表L3的工作指針,指向頭結(jié)點(diǎn)while(pa&&pb1)//L1和L2均非空if(pa->datadata){//L1中元素插入L3pc->next=pa;pc=pa;pa=pa->next;}elseif(pa->data>pb1->data){//L2中元素插入L3pc->next=pb1;pc=pb1;pb1=pb1->next;}else{pc->next=pa;pc=pa;pa=pa->next;pb1=pb2=pb1->n
5、ext;}if(pa)pc->next=pa;//若pa未到尾,將pc指向paelsepc->next=pb1;//若pb1未到尾,將pc指向pb1return(L3);}voiddisplay(LinkList*L){LinkList*head;head=L->next;do{printf("%dt",head->data);head=head->next;}while(head!=NULL);}voidmain(){intan,bn;LinkList*L1,*L2,*L3;L1=(LinkList*)malloc(sizeof(LinkList)
6、);L2=(LinkList*)malloc(sizeof(LinkList));printf("請(qǐng)輸入集合A中元素的個(gè)數(shù):");scanf("%d",&an);*L1=*CREATLISTF(L1,an);printf("集合A的元素為:");display(L1);printf("請(qǐng)輸入集合B中元素的個(gè)數(shù):");scanf("%d",&bn);*L2=*CREATLISTF(L2,bn);printf("集合B的元素為:");display(L2);L3=merge(L1,L2);printf("交集為:");displ
7、ay(L3);}實(shí)驗(yàn)二typedefstructnode{intcoef;intexp;structnode*next;}polynode;polynode*Creat1polynode();polynode*Creat2polynode();polynode*subpolynode(polynode*ha,polynode*hb);polynode*addpolynode(polynode*ha,polynode*hb);#include#includeintmain(){polynode*ha,*hb,*hc,
8、*hd,*p;ha=Creat1polynode();p=ha->next;printf("輸