一、定义单链表结构
- 代码:
typedef int linkType; ///< 定义链表结点数据域数据类型
/// @brief 链表结点定义
typedef struct t_linkNode
{
struct t_linkNode* pnext; ///< 结点指针域
linkType data; ///< 结点数据域
}myLNode;
/// @brief 链表结构定义
typedef struct t_linkList
{
myLNode* phead; //< 链表头结点指针
}myLinkList;
二、销毁单链表
1、思路
- 代码:
void xxx_destroy(myLinkList* plist)
{
if (plist == NULL)
{
return;
}
xxx_destroy_(plist->phead);
free(plist->phead);
plist->phead = NULL;
}
void xxx_destroy_(myLNode* phead)
{
if (phead == NULL)
{
return;
}
myLNode* pdel = phead->pnext;
while (pdel != NULL)
{
phead->pnext = pdel->pnext;
free(pdel);
pdel = phead->pnext;
}
}
标签:结点,pdel,销毁,phead,plist,单链,DS,pnext
From: https://www.cnblogs.com/kxwslmsps/p/17125255.html