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

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


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

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