Creating a dynamic linked list is the connection of nodes.
(1) Dynamic node generation
(2) Input node data
(3) Link the nodes together
Cases:
typedef struct DATA
{
Char num[20];
Char name[10];
char sex;
float 中文版;
Float Chinese;
float math;
};
typedef struct NODE
{
struct Data data;//struct type//struct-body nesting
struct node* next;//structural body pointer type
}node,*pnode;
Pnode Phead=null;
Pnode Ptail=null;
Create a Node
Pnode creat_node (int COUNT)
{
int i=0;
Pnode Pnew=null;
for (i=0;i<count;i++)//count is a node count
{
pnew= (pnode) malloc (sizeof (node));//Create a new node
printf ("Please enter information for%d students: \ n", (i+1));
printf ("School Number: \ n");
scanf ("%s", pnew->data.num);
printf ("Name: \ n");
scanf ("%s", pnew->data.name);
printf ("Sex: \ n");
scanf ("\n%c", &pnew->data.sex);
printf ("English: \ n");
scanf ("%f", &pnew->data.english);
printf ("Language: \ n");
scanf ("%f", &pnew->data.chinese);
printf ("Math: \ n");
scanf ("%f", &pnew->data.math);
if (Ptail)
{
ptail->next=pnew;//the first future node.
Ptail=pnew;
}
Else
{
phead=ptail=pnew;//first Node
}
pnew->next=null;
}
return phead;
}
This article is from the "Linux_woniu" blog, make sure to keep this source http://llu1314.blog.51cto.com/5925801/1965329
Creation of dynamic link list in C language