Home > Back-end >  Lead the singly linked list of nodes of a problem
Lead the singly linked list of nodes of a problem

Time:10-01

Bosses, please, there's no need to la - & gt; The data or la - & gt; Next, such as how to write?

CodePudding user response:

Pointer to La applying to p, q, pointer for Lb applying to t, with p, q traversing at La on Lb

CodePudding user response:

reference 1st floor gets_s response:
pointer for La applying to p, q, pointer for Lb applying to t, p, q traversing the La to Lb
for bosses to write a little code

CodePudding user response:

#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;
}

CodePudding user response:

reference gets_s reply: 3/f
# 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;
}

haste to write code, there may be a bug??????

CodePudding user response:

Enn... "Don't access list of any details in the title" and "sequential reading la" seems to be contradictions

CodePudding user response:

Create list la, then apply a Lb head, let the list Lb also point to la - & gt; Next; This lb can also access the list of data in a,
  • Related