带有头节点的单链表(学生信息管理)
发布时间
阅读量:
阅读量
目标: 每条数据包含学生的编号及其对应的成绩。
具体要求如下:
(1)构建一个链表结构,其中每个节点用于存储一个学生的信息;
(2)按照链表中的排列顺序,依次输出每个学生的信息;
(3)输入特定的学生编号后,进行查找操作。如果链表中存在该编号,则显示对应的学生成绩;否则输出"NO FOUND!"
#include "stdio.h"
#include "stdlib.h"
struct Node
{
int data; //编号
int score; //分数
struct Node*next;
};
//创建链表
struct Node*create( )
{
int i,data,score;
struct Node *p,*pre,*head; //*p临时节点,*pre表示当前节点,*head表示头节点
head =(struct Node*) malloc(sizeof(struct Node));
head->next=NULL;//头节点不需要数据域
pre=head; //当前节点为头节点
for (i=0;i<5;i++)
{
p = (str
全部评论 (0)
还没有任何评论哟~
