删除链表中最小的一个结点

include <stdio.h>

include <stdbool.h>

include <stdlib.h>

// 指的是单向链表中的结点有效数据类型,用户可以根据需要进行修改
typedef int DataType_t;

// 构造链表的结点,链表中所有结点的数据类型应该是相同的
typedef struct LinkedList
{
DataType_t data; // 结点的数据域
struct LinkedList *next; // 结点的指针域

} LList_t;
/*******************************************************************
*

  • 函数名称: MinDelate

  • 函数功能: 删除链表中最小的一个结点

  • 函数参数: LList_t *Head

  • 返回结果: 插入成功或否

  • 注意事项: None

  • 函数作者: 1810866453@163.com

  • 创建日期: 2024/04/22

  • 修改历史:

  • 函数版本: V1.0

  • *****************************************************************/
    bool LList_MinDelate(LList_t *Head)
    {
    LList_t *Phead1 = Head->next;
    LList_t *Phead2 = Head->next;
    LList_t *Phead3 = Head->next;
    int min = Phead1->data;
    int count;
    // 判断链表是否为空
    if (NULL == Head->next)
    {
    return false;
    }

    while (Phead1->next)
    {
    if (Phead1->data < min)
    min = Phead1->data;
    }
    while (Phead2->next)
    {
    count++;
    if (min == Phead2)
    break;
    }
    for (int i = 0; i < count; i++)
    {
    Phead2 = Phead2->next;
    }
    for (int j = 0; j <= count; j++)
    {
    Phead3 = Phead3->next;
    }
    Phead2->next = Phead3->next;
    Phead3->next = NULL;
    free(Phead3);
    return true;
    }

posted @ 2024-04-22 20:42  Zeratul$$$  阅读(19)  评论(0)    收藏  举报