C Language: Establish a simple static linked list, which consists of 3 student data nodes, which requires the output of data from each node.

Source: Internet
Author: User

Establish a simple static linked list, which consists of 3 student data nodes, which require the output of data from each node.

Solution: The first1the start address of a node is assigned to the head pointerHead, the first2the start address of a node is assigned to the1a node.Nextmember, the first3the start address of a node is assigned to the2a node.Nextmembers. Section3a node.Nextmembers giveNULL, which forms a linked list. In order to create a linked list, theHeadPointinganode,A.nextPointingbnode,B.nextPointingCnode,C.next=nullthe role is to makeC.nextdoes not point to any useful storage unit.

Program:

#include <stdio.h>

struct Student

{

int num;

Float score;

struct Student *next;

};

int main ()

{

struct Student A, B, C, *head, *p;

A.num = 10101; A.score = 89.5;

B.num = 10103; B.score = 90;

C.num = 10107; C.score = 85;

Head = &a;

A.next = &b;

B.next = &c;

C.next = NULL;

p = head;

Do

{

printf ("Num=%ld score=%5.1f\n", P->num, P->score);

p = p->next;

} while (P! = NULL);

return 0;

}

Results:

num=10101 score= 89.5

num=10103 score= 90.0

num=10107 score= 85.0

Please press any key to continue ...


This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1750274

C Language: Establish a simple static linked list, which consists of 3 student data nodes, which requires the output of data from each node.

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.