一、单链表结构定义
typedef void(myOpFunType)(void*); ///< 定义操作函数类型
typedef int linkType; ///< 定义链表结点数据域数据类型
/// @brief 链表结点定义
typedef struct t_linkNode
{
struct t_linkNode* pnext; ///< 结点指针域
linkType data; ///< 结点数据域
}myLNode;
/// @brief 链表结构定义
typedef struct t_linkList
{
myLNode* phead; //< 链表头结点
}myLinkList;
二、创建单链表函数:从键盘输入元素创建单链表
/// @brief 通过键盘输入元素创建单链表
/// @param plist 链表指针
/// @param flag 当从键盘输入的内容与flag相等时,结束键盘输入
void xxx_input(myLinkList* plist, linkType flag)
{
if (plist == NULL)
{
return;
}
xxx_input_(plist->phead, flag);
}
void xxx_input_(myLNode* phead, linkType flag)
{
if (phead == NULL)
{
return;
}
myLNode* p = phead;
myLNode* pnew = NULL;
linkType data;
printf("请输入链表元素序列:");
while (scanf_s ("%d", &data), data != flag)
{
pnew = (myLNode*)malloc(sizeof(myLNode));
if (pnew == NULL)
{
break;
}
pnew->data = data;
pnew->pnext = NULL;
p->pnext = pnew;
p = pnew;
}
}
标签:单链,创建,myLNode,pnew,链表,flag,键盘输入,data From: https://www.cnblogs.com/kxwslmsps/p/17120570.html