Home > other >  Help bosses
Help bosses

Time:10-06

Code can run, but entered a list of values, press enter, no reaction, want to know where is wrong and how to modify the code below
#include
#include
Typedef int Datatype.
Typedef struct Node
{Datatype data;
Struct Node * next;
} Node, * LinkList;
//create a singly linked list
LinkList creat ()
{LinkList L;
The Node * p, * r;
L=(LinkList) malloc (sizeof (Node));
L - & gt; Next=NULL;
R=L;
int x;
The scanf (" % d ", & amp; X);
While (x! )
='\ n'{p=(*) malloc (sizeof (Node));
P - & gt; Data=https://bbs.csdn.net/topics/x;
R - & gt; Next=p;
R=p;
The scanf (" % d ", & amp; X);
}
R - & gt; Next=NULL;
return L;
}
//merge singly linked list
LinkList comber (LinkList La, LinkList Lb)
{LinkList Lc;
Node * pa, pb, * r;
Lc=La;
Pa=La - & gt; Next;
Pb=Lb - & gt; Next;
Lc - & gt; Next=NULL;
R=Lc;
While (pa& & Pb)
{if (pa - & gt; Data<=pb - & gt; Data)
{r - & gt; Next=pa; R=pa; Pa=pa - & gt; Next; }
The else
{r - & gt; Next=pb; R=pb; Pb=pb - & gt; Next; }
}
If (pa) r - & gt; Next=pa;
The else r - & gt; Next=pb;
Free (Lb);
Return the Lc;
}
//input list
Void printL (LinkList L)
{Node * r;
R=L;
R=r - & gt; Next;
While (r - & gt; Next!=NULL)
{printf (" % d ", r - & gt; The data);
R=r - & gt; Next;
}
printf("\n");
}
//the main function
Void main ()
{printf (" please enter the first list: ");
LinkList A=creat ();
Printf (" please enter the second list: ");
LinkList B=creat ();
LinkList C=comber, (A, B);
PrintL (C);
}

  • Related