Home > Back-end >  Two order list synthesis problem of an ordered list
Two order list synthesis problem of an ordered list

Time:10-30

#include
#include
#include
Typedef struct LNode {
int data;
Struct LNode * next;
} LNode * Linklist;

Void Createlist (Linklist * L, int n)
{
(* L)=(Linklist) malloc (sizeof (LNode));
(* L) - & gt; Next=NULL;
Linklist p=* L;
int i;
for(i=0; i{
P=(Linklist) malloc (sizeof (LNode));
Printf (" please input element value: ");
The scanf (" % 2 d ", & amp; p-> The data);
p-> Next=(* L) - & gt; next;
(* L) - & gt; Next=p;
}

}

Void Printlist (Linklist L)
{
L=L - & gt; next;

While (L)
{
Printf (" % d, L - & gt; The data);
L=L - & gt; next;
}
Printf (" \ n \ n \ n ");

return;
}

Void Mergelist (Linklist * la, Linklist * lb, Linklist * lc)
{
La Linklist pa=(*) - & gt; next;
Linklist pb=(* lb) - & gt; next;
Linklist PC=(* la);
While (pa& & Pb)
{
If ((pa - & gt; Data) & lt;=(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;
}
}
While (pa)
{
PC - & gt; Next=pa;
PC=pa;
Pa=pa - & gt; next;
}
While (pb)
{
PC - & gt; Next=pb;
PC=pb;
Pb=pb - & gt; next;
}


}

The main ()
{
Linklist la, lb, lc;

Int n, m;
Printf (" please input the length of the first list: ");
The scanf (" % d ", & amp; N);
Createlist (& amp; La, n);
Printf (" please enter the second chain length, ");
The scanf (" % d ", & amp; M);
Createlist (& amp; Lb, m);
Mergelist (& amp; La, & amp; Lb, & amp; Lc);
Printlist (lc);
}

Would you please tell me why the great god I this program output result?
  • Related