Home > Back-end >  Please help to have a look at the code! Thank you very much! (urgent!
Please help to have a look at the code! Thank you very much! (urgent!

Time:03-19

# include
# include
Typedef int ElemType;
Typedef struct LNode
{
ElemType data;
Struct Lnode * next;
} LNode * LinkList;
Void CreateList_L LinkList (L)
{
L=(LinkList) malloc (sizeof (LNode));
L - & gt; Next=NULL;
int i;
LinkList p, q;
P=L;
char c;
For (;; I++)
{
While (p - & gt; Next) p=p - & gt; next;
Q=(LinkList) malloc (sizeof (LNode));
The scanf (" % d ", & amp; Q - & gt; The data);
p-> Next=q;
Q - & gt; Next=NULL;
If (c=getchar ()=='\ n') break;
}
}
Int main ()
{
LinkList LA, LB, LC;
CreateList_L (LA);
CreateList_L (LB);
LC=(LinkList) malloc (sizeof (LNode));
LC - & gt; Next=NULL;
LinkList p=LA, q=LB, l1, l2,
For (p=LA; p-> Next!=NULL; P=p - & gt; Next)
{
For (q=LB; Q - & gt; Next!=NULL; Q=q - & gt; Next)
{
If ((q - & gt; Data)==(p - & gt; Data))
{
L2=LC;
While (l2 - & gt; Next) l2=l2 - & gt; next;
L1=(LinkList) malloc (sizeof (LNode));
L1=l2;
L1 - & gt; data=https://bbs.csdn.net/topics/q-> data;
L2 - & gt; Next=l1;
L1 - & gt; Next=NULL;
}
}
}
P=LA;
LinkList u=LA;
While (p - & gt; Next)
{
U=p;
P=p - & gt; next;
Free (u);
}
Q=LB.
U=LB;
While (q - & gt; Next)
{
U=q;
Q=q - & gt; next;
Free (u);
}
L2=LC;
While (l2 - & gt; Next)
{
L2=l2 - & gt; next;
If (l2 - & gt; Next==NULL) printf (" % d \ n ", l2 - & gt; The data);
The else printf (" % d ", l2 - & gt; The data);
}
return 0;
}

CodePudding user response:

Pointer to a parameter, only by modifying the content of his point in the function, and can't modify his point,

CodePudding user response:

 # include 
# include

Typedef int ElemType;
Typedef struct LNode
{
ElemType data;
//struct Lnode * next;
Struct LNode * next;
} LNode * LinkList;

//void CreateList_L LinkList (L)
Void CreateList_L (LinkList * L)
{
* L=(LinkList) malloc (sizeof (LNode));
(* L) - & gt; Next=NULL;
int i;
LinkList p, q;
P=* L;
char c;
//for (;; I++)
For (;; )
{
While (p - & gt; Next)
P=p - & gt; next;
Q=(LinkList) malloc (sizeof (LNode));
The scanf (" % d ", & amp; Q - & gt; The data);
Printf (" % d \ n ", q - & gt; The data);
p-> Next=q;
Q - & gt; Next=NULL;
//if (c=getchar ()=='\ n') break;
If ((c=getchar ())=='\ n')//a less brackets
break;
}
}
Int main ()
{
LinkList LA, LB, LC;
CreateList_L (& amp; LA);
CreateList_L (& amp; LB);
LC=(LinkList) malloc (sizeof (LNode));
LC - & gt; Next=NULL;

LinkList p=LA, q=LB, l1, l2,
//for (p=LA; p-> Next!=NULL; P=p - & gt; Next)
For (p=LA - & gt; next; P!=NULL; P=p - & gt; Next)
{
//for (q=LB; Q - & gt; Next!=NULL; Q=q - & gt; Next)
For (q=LB - & gt; next; Q!=NULL; Q=q - & gt; Next)
{
If ((q - & gt; Data)==(p - & gt; Data))
{
L2=LC;
While (l2 - & gt; Next)
L2=l2 - & gt; next;
L1=(LinkList) malloc (sizeof (LNode));
//l1=l2;
L1 - & gt; data=https://bbs.csdn.net/topics/q-> data;
L2 - & gt; Next=l1;
L1 - & gt; Next=NULL;
L2=l1;
}
}
}

P=LA;
LinkList u=LA;
While (p - & gt; Next)
{
U=p;
P=p - & gt; next;
Free (u);
}
Q=LB.
U=LB;
While (q - & gt; Next)
{
U=q;
Q=q - & gt; next;
Free (u);
}

L2=LC - & gt; next;
//while (l2 - & gt; Next)
While (l2)
{
/*
If (l2 - & gt; Next==NULL) printf (" % d \ n ", l2 - & gt; The data);
The else printf (" % d ", l2 - & gt; The data);
*/
Printf (" % d ", l2 - & gt; The data);
L2=l2 - & gt; next;
}
putchar(10);
return 0;
}


For your reference ~
  • Related