Creation of dynamic link list in C language

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.