List three basic operations (combined list of unordered list in increasing order of intersection)

#include<stdio.h>
#include<malloc.h>


struct {LinkNode typedef
int Data;
struct * Next LinkNode;
} LinkNode;
LinkNode create_LNode * (L * LinkNode) {// create a linked list, the first node with no special
LinkNode newp *, * tail;
int A;
L = NULL; / / Create a without head node list
printf ( "Please input nodes: \ n-");
Scanf ( "% D", & a);
the while (a = -. 1!) {
newp = (LinkNode *) the malloc (the sizeof ( LinkNode));
newp-> Next = NULL;
newp-> Data = A;
IF (== L NULL) {
L = tail newp =;
}
the else {
tail-> Next newp =; newp = tail;
}
Scanf ( " D% ", & A);
}
return L;
}


LinkNode *LinkNode_Merge(LinkNode *La,LinkNode *Lb){//增序链表的合并,破坏La,Lb,组合Lc
LinkNode *Lc,*pa,*pb,*tail;
pa=La->next;
pb=Lb->next;
free(Lb);
//Lc=tail=(LinkNode *)malloc(sizeof(LinkNode));
Lc=tail=La;
while(pa!=NULL&&pb!=NULL){
if(pb->data<=pa->data){
tail->next=pb;
tail=pb;
pb=pb->next;
}
else{
tail->next=pa;
tail=pa;
pa=pa->next;
}
}
if(pa!=NULL){
tail->next=pa;
}
else{
tail->next=pb;
}
return Lc;

}


LinkNode *LinkNode_Intersection(LinkNode *La,LinkNode *Lb){//无序链表LA交Lb
LinkNode *Lc,*tail,*pa,*pb,*newp;
Lc=NULL;//创建无头结点的Lc
for(pa=La;pa;pa=pa->next){
for(pb=Lb;pb;pb=pb->next){
if(pb->data==pa->data){
newp=(LinkNode *)malloc(sizeof(LinkNode));
newp->data=pa->data;
newp->next=NULL;
if(Lc==NULL){
Lc=newp;
tail=newp;
}
else{
tail->next=newp;
tail=newp;
}
break;
}
}
}
return Lc;
}


void print (LinkNode * L) { // output functions
LinkNode * P;
for (L = P; P; P = p-> Next) {
the printf ( "% D", p-> Data);
}
the printf ( "\ n-");
}
int main () {
LinkNode * La, Lb *, * Lc of;
La = create_LNode (La);
Print (La);
Lb = create_LNode (Lb);
Print (Lb);

// = Lc of LinkNode_Merge ( La, Lb); // merge linked list in increasing order of
Lc = LinkNode_Intersection (La, Lb) ; // unordered list intersection
Print (Lc of);


return 0;
}

Guess you like

Origin www.cnblogs.com/jiafeng1996/p/11286101.html