一、定义单链表结构
- 代码:
typedef int linkType; ///< 定义链表结点数据域数据类型
/// @brief 链表结点定义
typedef struct t_linkNode
{
struct t_linkNode* pnext; ///< 结点指针域
linkType data; ///< 结点数据域
}myLNode;
/// @brief 链表结构定义
typedef struct t_linkList
{
myLNode* phead; //< 链表头结点指针
}myLinkList;
二、定位尾结点
1、思路
- 代码:
/// @brief 定位链表尾结点
/// @param plist
/// @return 返回定位结果
/// @retval 非NULL:尾结点地址
/// @retval NULL:定位失败
myLNode* xxx_locateTail(myLinkList* plist)
{
if (plist == NULL)
{
return NULL;
}
return xxx_locateTail_(plist->phead);
}
myLNode* xxx_locateTail_(myLNode* phead)
{
if (phead == NULL || phead->pnext == NULL)
{
return NULL;
}
myLNode* p = phead;
while (p->pnext != NULL)
{
p = p->pnext;
}
return p;
}
标签:结点,单链,表尾,myLNode,链表,phead,return,NULL,DS
From: https://www.cnblogs.com/kxwslmsps/p/17125270.html