# define FALSE 0
# define OK 1
# define the ERROR 0
# define INFEASIBLE - 1
# define OVERFLOW - 2
# define NULL 0
#include
#include
Typedef int the Status;
typedef int ElemType;
Typedef struct LNode {
ElemType data;
Struct LNode * next;
} LNode * LinkList;
Typedef LNode * LinkList;
Void CreateList_L (LinkList L, int n);
Void MergeList_L (LinkList La LinkList Lb, LinkList Lc);
Void OutputList (LinkList L);
Void CreateList_L (LinkList L, int n) {
int i;
LinkList p;
L=(LinkList) malloc (sizeof (LNode));
L - & gt; next=NULL;
For (I=0; I & lt; n; + + I) {
P=(LinkList) malloc (sizeof (LNode));
The scanf (" % d ", & amp; P - & gt; The data);
P - & gt; Next=L - & gt; next; L - & gt; Next=p;
}
}//CreateList_L
Void MergeList_L (LinkList La LinkList Lb, LinkList Lc) {
LinkList pa, pb, PC;
Pa=La - & gt; next; Pb=Lb - & gt; next;
Lc=PC=La;
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;
Free (Lb);
}//MergeList_L
Void OutputList (LinkList L) {
LinkList q;
Q=L - & gt; next;
While (q) {
Printf (" % d ", q - & gt; The data);
Q=q - & gt; next;
}
}//OutputList_L
Int main () {
LinkList L1, L2, L3.
Printf (" do enter the element of L1: \ n ");
CreateList_L (L1, 4);
Printf (" do enter the element of L2: \ n ");
CreateList_L (L2, 4);
Printf (" The LinkList L1 is: \ n ");
OutputList (L1);
Printf (" The LinkList L2 is: \ n ");
OutputList (L2);
MergeList_L (L1, L2, L3);
Printf (" The LinkList L3 is: \ n ");
OutputList (L3);
return 0;
}
CodePudding user response:
My singly linked lists can enter but cannot output, no errors of grammar, every brother please help have a lookCodePudding user response:
CodePudding user response:
# include
#include
# define TRUE 1
# define FALSE 0
# define OK 1
# define the ERROR 0
# define INFEASIBLE - 1
# define OVERFLOW - 2
//# define NULL (0) (void *)
Typedef int the Status;
typedef int ElemType;
Typedef struct LNode {
ElemType data;
Struct LNode * next;
} LNode * LinkList;
Typedef LNode * LinkList;
Void CreateList_L (LinkList * L, int n);
Void MergeList_L (LinkList La LinkList Lb, LinkList * Lc);
Void OutputList (LinkList L);
Void CreateList_L (LinkList * L, int n) {
int i;
LinkList p;
* L=(LinkList) malloc (sizeof (LNode));
(* L) - & gt; next=NULL;
For (I=0; I & lt; n; + + I) {
P=(LinkList) malloc (sizeof (LNode));
The scanf (" % d ", & amp; P - & gt; The data);
P - & gt; Next=(* L) - & gt; next;
(* L) - & gt; Next=p;
}
}//CreateList_L
Void MergeList_L (LinkList La LinkList Lb, LinkList * Lc) {
LinkList pa, pb, PC;
Pa=La - & gt; next; Pb=Lb - & gt; next;
* Lc=PC=La;
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;
Free (Lb);
}//MergeList_L
Void OutputList (LinkList L) {
LinkList q;
Q=L - & gt; next;
While (q) {
Printf (" % d ", q - & gt; The data);
Q=q - & gt; next;
}
}//OutputList_L
Int main () {
LinkList L1, L2, L3.
Printf (" do enter the element of L1: \ n ");
CreateList_L (& amp; L1, 4);
Printf (" do enter the element of L2: \ n ");
CreateList_L (& amp; L2, 4);
Printf (" The LinkList L1 is: \ n ");
OutputList (L1);
Printf (" The LinkList L2 is: \ n ");
OutputList (L2);
MergeList_L (L1, L2, & amp; L3);
Printf (" The LinkList L3 is: \ n ");
OutputList (L3);
return 0;
}
For your reference ~
Try this version, and then compare the difference between these two code, find out the problems of its own;
In addition, the key to learn parameters, incoming parameters, efferent parameters, etc.