数据结构链表笔试题

image

/**********************************************************************************************
*   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          : liaojx2016@126.com
*   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;
}
posted @ 2024-04-23 09:11  沉舟道人  阅读(6)  评论(0编辑  收藏  举报