#include
Typedef struct lnode
{
The int data;
Struct lnode * next;
} londe, * linklist;
Void input (linklist & amp; L)
{
Linklist p, r;
L=new londe;
L - & gt; Next=NULL;
P=l;
R=new londe;
The scanf (" % d ", & amp; R - & gt; The data);
R - & gt; Next=NULL;
While (r - & gt; The data! )
='*'{
R=new londe;
R=r - & gt; next;
The scanf (" % d ", & amp; R - & gt; The data);
}
R - & gt; Next=NULL;
P - & gt; Next=r;
}
Void the output (linklist l)
{
Linklist p;
P=l - & gt; next;
While (p!=NULL)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; next;
}
}
Londe * unlist (linklist & amp; La, linklist & amp; Lb, linklist & amp; Lc)
{
Linklist pa, pb, PC;
Pa=la - & gt; next;
Pb=lb - & gt; next;
Lc=la;
PC=lc;
While (pa& & Pb)
{
If (pa - & gt; Data<=pb - & gt; Data)
{
PC - & gt; Next=pa;
PC=pa;
Pa=pa - & gt; next;
}
The else
{
PC - & gt; Next=pb;
PC=pb;
Pb=pb - & gt; next;
}
}
PC - & gt; Next=pa? Pa: pb;
The delete lb.
Return the PC;
}
Int listlength linklist (l)
{
int i=0;
Linklist p;
P=l - & gt; next;
While (p!=NULL)
{
i++;
P=p - & gt; next;
}
Return the I;
}
Londe * jiaolist (linklist & amp; La, linklist & amp; Lb, linklist & amp; Lc)
{
Int GetElem (linklist l, int, int & amp; E);
Linklist pa, pb, PC, p;
Int m, n, I, x, e, a, b;
Pa=la - & gt; next;
Pb=lb - & gt; next;
PC=p;
M=listlength (la);
N=listlength (lb);
for(i=1; I<=m; I++)
For (x=1; x<=n; X++)
{
A=GetElem (la, I, e);
B=GetElem (lb, x, e);
If (a==b)
{
P=new londe;
P - & gt; data=https://bbs.csdn.net/topics/e;
}
}
Return the PC;
}
Int GetElem (linklist l, int, int & amp; E)
{
Linklist p;
P=l - & gt; next;
Int b, j;
While (p& & J{
P=p - & gt; next;
+ + j;
}
if(! P | | j> 1)
return -1;
B=p - & gt; The data;
Return b;
}
Londe * chalist (linklist & amp; La, linklist & amp; Lb, linklist & amp; Lc)
{
Linklist pa, pb, PC, p;
Int m, n, I, x, e, a, b;
Pa=la - & gt; next;
Pb=lb - & gt; next;
PC=p;
M=listlength (la);
N=listlength (lb);
for(i=1; I<=m; I++)
{
For (x=1; x<=n; X++)
{
A=GetElem (la, I, e);
B=GetElem (lb, x, e);
If (a!=b)
break;
}
If (a!=b)
{
P=new londe;
P - & gt; data=https://bbs.csdn.net/topics/a;
}
}
Return the PC;
}
Int main ()
{
Linklist la, lb, lc;
Printf (" please enter la elements: ");
Input (la);
Printf (" please enter lb elements: ");
Input (lb);
Printf (" and set: ");
The output (unlist (la and lb, lc));
Printf (" masked: ");
The output (jiaolist (la and lb, lc));
Printf (" a difference set: ");
The output (chalist (la and lb, lc));
return 0;
}
CodePudding user response:
void input (linklist & amp; L)
{
Linklist p, r;
L=new londe;
L - & gt; Next=NULL;
P=l;
R=new londe;
The scanf (" % d ", & amp; R - & gt; The data);
R - & gt; Next=NULL;
If # 1
While (r - & gt; The data!=1)
{
P - & gt; Next=r;
P=r;
R=new londe;
The scanf (" % d ", & amp; R - & gt; The data);
}
P - & gt; Next=NULL;
Free (r);//the last applied for space but not join list
# the else
While (r - & gt; The data! )
='*'{
R=new londe;
R=r - & gt; next;
The scanf (" % d ", & amp; R - & gt; The data);
}
R - & gt; Next=NULL;
P - & gt; Next=r;
# endif
}
Void the output (linklist l)
{
Linklist p;
P=l - & gt; next;
While (p!=NULL)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; next;
}
Putchar (10);
}
For your reference ~
Problem is how to use of the building Lord % d enter '*', of course, can also enter 42 is ok, but direct input * is not possible,
In addition, the original poster and set again, intersection, difference set, after notice o and sets, la, lb list has been corrected, reoccupy la, behind lb intersection and difference set is going to have a problem, you can think about this question?
CodePudding user response:
The