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.