学生成绩链表处理
要求: 本题要求实现两个函数,一个将输入的学生成绩组织成单向链表;另一个将成绩低于某分数线的学生结点从链表中删除
1.结构函数,创建
struct stud_node *createlist()
{
struct stud_node *head, *wei, *z;
head = wei = NULL;
int num;
scanf ("%d", &num);
while (num != 0)
{
z = (struct stud_node *)malloc (sizeof (struct stud_node));
scanf ("%s %d", z->name, &z->score);
z->num = num;
z->next = NULL;
if (head == NULL)
head = z;
else
wei->next = z;
wei = z;
scanf ("%d", &num);
}
return head;
}
2.结构函数,删除
struct stud_node *deletelist( struct stud_node *head, int min_score )
{
struct stud_node *p1, *p2;
while (head != NULL && head->score < min_score)
{
p2 = head;
head = head->next;
free(p2);
}
if (head == NULL)
return NULL;
p1 = head;
p2 = head->next;
while (p2 != NULL)
{
if (p2->score < min_score)
{
p1->next = p2->next;
free(p2);
}
else
p1 = p2;
p2 = p1->next;
}
return head;
}
** 希望能给你帮助,嘿嘿**