题目
答案
struct stud_node *createlist()
{
struct stud_node* head = (struct stud_node*)malloc(sizeof(struct stud_node));
head->next = NULL;
struct stud_node* p = head;
int ty;scanf("%d",&ty);
while(ty!=0)//尾插法创建链表
{
p->next = (struct stud_node*)malloc(sizeof(struct stud_node));
p = p->next;
scanf("%s %d",p->name,&p->score);
p->num = ty;
p->next = NULL;
scanf("%d",&ty);
}
return head;
}
struct stud_node *deletelist( struct stud_node *head, int min_score )
{
struct stud_node *p;
while(head!=NULL&&head->score<min_score){
p=head;
head=head->next;
}
if(head==NULL){
return NULL;
}
p=head;
while(p->next!=NULL){
if(p->next->score<min_score){
p->next=p->next->next;
}
else{
p=p->next;
}
}
return head;
}
测试点
注意
本题在删除节点时,一定要先对头指针进行判断和处理,因为头指针的删除逻辑与其它指针不同,需要单独处理。