Summary of a single-chain table without a header ---- dynamically create a linked list and a single-chain table ----

Source: Internet
Author: User

Summary of a single-chain table without a header ---- dynamically create a linked list and a single-chain table ----

1 # include "head. h "2 struct Student * creat () 3 {4 struct Student * head, * p1, * p2; // open up three struct pointers first, * head, (As the returned header pointer) 5 p1 = p2 = (struct Student *) malloc (LEN); 6 scanf_s ("% s % f", p1-> num, N, & p1-> score); // read the input information first, and Judge 7 head = NULL according to the read information; // first point the header pointer to a NULL pointer 8 n = 0; // count the number of members in the chain table 9 while (strcmp (p1-> num, "0 ")! = 0) // Based on the read information, "0" indicates the input termination label. If not 10 // 0, add 11 {12 ++ n to the linked list; // if it is not terminated, add a member 13 if (n = 1) head = p1; // first assign the starting address to the header pointer, because p1 will be moved back next, 14 // No header pointer information 15 else p2-> next = p1; // p1 is divided into two situations, when n = 1, p1 is assigned to the header pointer. next, p1 links 16 // The previous pointer p2-> next; 17 p2 = p1; // After the link is completed, p2 moves to p1. 18 p1 = (struct Student *) malloc (LEN); // then p1 continues to develop new memory storage members; 19 scanf_s ("% s % f", p1-> num, n, & p1-> score); // reads new member information, returns to the beginning, reads 20 // reads 21} 22 p2-> next = NULL; // It is the next of p2 as the end mark. Note that p1 is used to store the "0" 23 // The 24 return head condition is terminated; // return header pointer 25}

 

Related Article

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.