/**********************************************************************************************
* func name : Minnote_Del
* function : Delete the min node of link list
* func parameter :
* @Head :address of the head node
* return resuolt : Delete success result (true or failse)
* author : [email protected]
* date : 2024/04/21
* note : None
* modify history : None
* function section: v1.0
*
**********************************************************************************************/
bool MinNode_Del(LList_t *Head)
{
//错误判断,head为空链表
if (NULL == Head->next)
{
printf("linklist is empty,headdelete failed\n");
return false;
}
int min=Head->next->data;
LList_t *p=Head->next;//遍历指针
LList_t *pre=Head;//遍历指针的直接前驱指针
LList_t *MinNote=Head->next;//最小结点指针
LList_t *preMinNote=Head;//最小结点指针的直接前驱指针
//遍历,找出最小结点及其直接前驱
do
{
pre=p;
p=p->next;
if (min > p->data) {
min=p->data;
preMinNote=pre;
MinNote=p;
}
}
while (p->next);
//删除最小结点
preMinNote->next=MinNote->next;
MinNote->next=NULL;
free(MinNote);
return true;
}
标签:Head,min,笔试,next,链表,LList,MinNote,数据结构,指针
From: https://www.cnblogs.com/JinBool/p/18152079