Time:10-01
CodePudding user response:
pointer for La applying to p, q, pointer for Lb applying to t, p, q traversing the La to Lb
# include using namespace std; # define N 5 Typedef struct Lnode {int data; Struct Lnode * next; } Lnode * Linklist; //structure singly linked lists La Linklist Createndlist1 (int a [N]) {Linklist L; L=(Lnode *) malloc (sizeof (Lnode)); If (L==NULL) {Cout & lt; <"Error"; The exit (0); } The else L - & gt; Next=NULL; Linklist tail, p; Tail=L; int j; For (j=0; J & lt; N; J++) {P=(Lnode *) malloc (sizeof (Lnode)); If (p==NULL) {Cout & lt; <"Error"; The exit (0); } The else p - & gt; Next=NULL; P - & gt; Data=https://bbs.csdn.net/topics/a [j]; Tail - & gt; Next=p; Tail=p; } Tail - & gt; Next=NULL; Return the L; } //structure singly linked lists Lb Linklist CreatLinklist2 Linklist (La) {Linklist Lb. Lb=(Lnode *) malloc (sizeof (Lnode)); If (Lb==NULL) {Cout & lt; <"Error"; The exit (0); } The else Lb - & gt; Next=NULL; Linklist p, q, t; P=La; Q=p - & gt; Next; T=Lb. While (q) {P - & gt; Next=q - & gt; Next; Q - & gt; Next=NULL; T - & gt; Next=q; T=q; Q=p - & gt; Next; } Return Lb. } //output list Void putlist Linklist (L) {int i; Linklist p; P=L - & gt; Next; While (p!=NULL) {Cout & lt; P=p - & gt; Next; } Cout & lt; } Int main () {Int I, a, [N]. Printf (" please enter % d value of the list element: ", N); For (I=0; I & lt; N; I++) {cin> A, [I]. } Linklist La, Lb. La=Createndlist1 (a); Cout & lt; <"List La for:"; Putlist (La); Lb=CreatLinklist2 (La); Cout & lt; <"List Lb for:"; Putlist (Lb); return 0; }
Page link:https//www.codepudding.com/Backend/45552.html