一、单链表结构定义
typedef int linkType; ///< 定义链表结点数据域数据类型
/// @brief 链表结点定义
typedef struct t_linkNode
{
struct t_linkNode* pnext; ///< 结点指针域
linkType data; ///< 结点数据域
}myLNode;
/// @brief 链表结构定义
typedef struct t_linkList
{
myLNode* phead; //< 链表头结点
}myLinkList;
二、删除单链表中元素为x的第一个结点
/// @brief 删除链表中元素值为x的第一个结点
/// @param plist 链表指针
/// @param x 待删元素
/// @return 返回是否删除成功的标志
/// @retval ERROR(0):链表不存在,不可操作
/// @retval FALSE(0):找不到x元素结点,删除操作失败
status xxx_removeX(myLinkList* plist, linkType x)
{
if (plist == NULL)
{
return ERROR;
}
return xxx_removeX_(plist->phead, x);
}
status xxx_removeX_(myLNode* phead, linkType x)
{
if (phead == NULL || phead->pnext == NULL)
{
return ERROR;
}
myLNode* p = phead->pnext;
myLNode* pre = phead;
while (p != NULL && x != p->data)
{
pre = p;
p = p->pnext;
}
/// 若p==NULL,说明遍历完链表仍未找到x结点,跳出循环
if (p == NULL)
{
return FALSE;
}
pre->pnext = p->pnext;
p->pnext = NULL;
free(p);
p = NULL;
return OK;
}
标签:结点,单链,return,链表,phead,表中,NULL,pnext From: https://www.cnblogs.com/kxwslmsps/p/17120802.html