# include & lt; The malloc. H>
# include & lt; stdlib.h>
Typedef struct Node {
int data;//data domain
Struct Node * next;//pointer field
} node, * PNODE;
//function declaration
PNODE create_list ();
Void show_list (PNODE);
Bool empty_list (PNODE);
Void length_list (PNODE);
Bool insert_list (PNODE, int, int);
Int main () {
PNODE L=NULL;//
L=create_list ();//create the acyclic singly linked lists, the head node address is assigned to head dynamic memory allocation
Show_list (L);
Empty_list (L);
Insert_list (L, 3, 5);
Show_list (L);
Length_list (L);
return 0; } PNODE create_list ()//create a functional
{
Int len, val, I;
PNODE phead=(PNODE) malloc (sizeof (node));
If (phead==NULL)
{
Printf (" memory allocation failure ");
The exit (1);
}
PNODE p=phead;
P - & gt; Next=NULL;
Printf (" please enter the number list: ");
The scanf (" % d ", & amp; Len);
for(i=0; i
Printf (" % d a node value is: ", I + 1);
The scanf (" % d ", & amp; Val);
PNODE pnew=(PNODE) malloc (sizeof (node));
If (pnew==NULL)
{
Printf (" memory allocation failure ");
The exit (1);
}
Pnew - & gt; Data=https://bbs.csdn.net/topics/val;
P - & gt; Next=pnew;
Pnew - & gt; Next=NULL;
P=pnew;
}
Return phead; } void show_list (PNODE phead)//output traversal
{
PNODE p=phead - & gt; next;
While (p!=NULL)
{
Printf (" % d ", p - & gt; data);
P=p - & gt; next;
}
printf("\n");
}
Bool empty_list (PNODE phead)//whether the list is empty
{if (phead - & gt; Next=NULL)
return true;
}
Void length_list (PNODE phead)
{
int i=0;
PNODE p=phead - & gt; next;
While (p!=NULL)
{
i++;
P=p - & gt; next;
}
Printf (" list length is % d ", I);
}
Bool insert_list (PNODE phead, int n, int m)//insert the NTH element m
{
int i=0;
PNODE p=phead, s;
If (n & lt; 1) return false.
While (I & lt; N - 1 & amp; & p!=0)
{
i++;
P=p - & gt; next;
}
If (p=NULL) return false.
The else {
S=(PNODE) malloc (sizeof (node));
S - & gt; data=https://bbs.csdn.net/topics/m;
S - & gt; Next=p - & gt; next;
P - & gt; Next=s;
return true;
}
}
CodePudding user response:
# include & lt; stdio.h>
# include & lt; The malloc. H>
# include & lt; stdlib.h>
Typedef struct Node {
int data;//data domain
Struct Node * next;//pointer field
} node, * PNODE;
//function declaration
PNODE create_list ();
Void show_list (PNODE);
Bool empty_list (PNODE);
Void length_list (PNODE);
Bool insert_list (PNODE, int, int);
Int main ()
{
PNODE L=NULL;//
L=create_list ();//create the acyclic singly linked lists, the head node address is assigned to head dynamic memory allocation
Show_list (L);
Empty_list (L);
Insert_list (L, 3, 5);
Show_list (L);
Length_list (L);
return 0;
}
PNODE create_list ()//create a functional
{
Int len, val, I;
PNODE phead=(PNODE) malloc (sizeof (node));
If (phead==NULL)
{
Printf (" memory allocation failure ");
The exit (1);
}
PNODE p=phead;
P - & gt; Next=NULL;
Printf (" please enter the number list: ");
The scanf (" % d ", & amp; Len);
for(i=0; i{
Printf (" % d a node value is: ", I + 1);
The scanf (" % d ", & amp; Val);
PNODE pnew=(PNODE) malloc (sizeof (node));
If (pnew==NULL)
{
Printf (" memory allocation failure ");
The exit (1);
}
Pnew - & gt; Data=https://bbs.csdn.net/topics/val;
P - & gt; Next=pnew;
Pnew - & gt; Next=NULL;
P=pnew;
}
Return phead;
}
Void show_list (PNODE phead)//output traversal
{
PNODE p=phead - & gt; next;
While (p!=NULL)
{
Printf (" % d ", p - & gt; data);
P=p - & gt; next;
}
printf("\n");
}
Bool empty_list (PNODE phead)//whether the list is empty
{
//if (phead - & gt; Next=NULL)
If (phead - & gt; Next==NULL)
return true;
The else
return false;
}
Void length_list (PNODE phead)
{
int i=0;
PNODE p=phead - & gt; next;
While (p!=NULL)
{
i++;
P=p - & gt; next;
}
Printf (" list length is % d ", I);
}
Bool insert_list (PNODE phead, int n, int m)//insert the NTH element m
{
int i=0;
PNODE p=phead, s;
If (n & lt; 1)
return false;
While (I & lt; N - 1 & amp; & p!=0)
{
i++;
P=p - & gt; next;
}
//if (p=NULL)
If (p==NULL)
return false;
The else {
S=(PNODE) malloc (sizeof (node));
S - & gt; data=https://bbs.csdn.net/topics/m;
S - & gt; Next=p - & gt; next;
P - & gt; Next=s;
return true;
}
}
For your reference ~