1 Star 0 Fork 0

CoderQi/cg初学

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Slist.c 780 Bytes
一键复制 编辑 原始数据 按行查看 历史
CoderQi 提交于 2023-01-09 22:04 +08:00 . 231_9
#include"Slist.h"
//实现打印函数
void SListPrint(SLTNode* phead)
{
SLTNode* cur = phead;//用一个cur存头指针
while (cur != NULL)
{
printf("%d->", cur->data);
cur = cur->next;//使下一次循环中cur指向下一个结点直到cur为空
}
printf("NULL");
}
//实现尾插函数
void SListPushBack(SLTNode** pphead, SLTDateType x)
{
SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));//申请新空间存在newnode中
newnode->data = x;
newnode->next = NULL;//尾插所以置空
if (*pphead==NULL)//链表为空的情况
{
*pphead = newnode;
}
else//不为空
{
SLTNode* tail = *pphead;//防止头部丢失,设置临时变量
//找到尾节点
while (tail->next != NULL)//从链表头部往后走
{
tail = tail->next;
}
tail->next = newnode;//将尾节点置为新申请的空间
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/programmercg/cg-beginner.git
git@gitee.com:programmercg/cg-beginner.git
programmercg
cg-beginner
cg初学
master

搜索帮助