if(ptr->num<=ptr2->num){
if(head==ptr2) head=ptr;
else ptr1->next=ptr;
ptr->next=ptr2;
}
else{
ptr2->next=ptr;
ptr->next=NULL;
}
}
return head;
}
//删除操作
struct stud_node *DeleteDoc(struct stud_node *head,int num)
{
struct stud_node *ptr1,*ptr2;
//要被删除节点为表头结点
while(head!=NULL && head->num==num){
ptr2=head;
head=head->next;
free(ptr2);
}
if(head==NULL){
return NULL;
}
//要被删除节点为非表头节点
ptr1=head;
ptr2=head->next;//从表头的下一节点搜索所有符合删除的节点
while(ptr2!=NULL){
if(ptr2->num==num){
ptr1->next=ptr2->next;
free(ptr2);
}
else{
ptr1=ptr2;
ptr2=ptr1->next;
}
}
return head;
}
//遍历操作
void Print_Stu_Doc(struct stud_node *head)
{
struct stud_node *ptr;
if(head==NULL){
printf("\n No Recordsn \n");
return;
}
printf("\nThe students'Records Are:\n");
printf("Num\t Name\t Score\n");
for(ptr=head;ptr!=NULL;ptr=ptr->next){
printf("%d\t %s\t %d\n",ptr->num,ptr->name,ptr->score);
}
}
链表11111
最新推荐文章于 2024-07-15 12:54:34 发布