Source code (C language Implementation)
①. Constructing a linked list node
typedef struct node //A separate node
{
int data;//data field
struct Node * pnext;//pointer field
}node,* PNODE;
②. Initialization of the list
      pnode init_list ()
{
int len;//The length of the linked list
int i;//Loop Switch
int the value of the val;//node
Pnode Phead = (pnode) malloc (sizeof (node));//build up the knot
if (Null==phead)
{
printf ("List dynamic allocation failed!") Program Terminated! \ n ");
Exit (-1);
}
Else
{
printf ("Please enter the length of the list to create len=");
scanf ("%d", &len);
if (0==len)
{
Phead->pnext = NULL;
return phead; The processing of the empty linked list
}
if (len<0)//For processing with a negative length
{
printf ("The length of the linked list cannot be negative!") \ n ");
Exit (-1);
}
Pnode Ptail = Phead;//ptail points to the tail node
Ptail->pnext = NULL;
for (i=0;i<len;i++)
{
Pnode pnew = (pnode) malloc (sizeof (node));//Create a new node
printf ("Please enter the number of%d nodes val =", i+1);
scanf ("%d", &val);
Pnew->data = val; Assign value
Ptail->pnext = pnew; Connect a new node
Ptail = pnew; Ptail Move back
}
Ptail->pnext = null;//The pointer field of the last node must be empty
return phead; Returns the head node used to represent the entire list.
}
}
Linked list source code (C language Implementation)