struct stud_node *createlist() { struct stud_node *head, *tail, *p; int num, score; char name[20]; head = tail = NULL; scanf("%d", &num); while (num != 0) { scanf("%s %d", name, &score); p = (struct stud_node *)malloc(sizeof(struct stud_node)); p->num = num; strcpy(p->name, name); p->score = score; p->next = NULL; if (head == NULL) head = p; else tail->next = p; tail = p; scanf("%d", &num); } return head; }

struct stud_node *deletelist(struct stud_node *head, int min_score) { struct stud_node *p, *q; while (head != NULL && head->score < min_score) { p = head; head = head->next; free(p); } if (head == NULL) return NULL; p = head; q = head->next; while (q != NULL) { if (q->score < min_score) { p->next = q->next; free(q); q = p->next; } else { p = q; q = q->next; } } return head; }

C语言单向链表操作:创建学生成绩链表并删除低于分数线学生

原文地址: https://www.cveoy.top/t/topic/nydP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录