Node *current; // 当前节点指针
current = *nextp; // 最初当前节点为nextp指针指向的节点
// 查找新插入节点的位置
while (current != NULLcurrent-valuenewValue)
{
nextp = ¤t-next;
current = current-next;
}
// 为新节点分配内存
newNode = (Node *)malloc(sizeof(Node));
if (newNode == NULL)
return FALSE;
newNode-value = https://www.04ip.com/post/newValue;
// 统一了插入的步骤 。即:每次插入,都是前一个指针指向新节点 , 新节点指向下一个节点
*nextp = newNode;
newNode-next = current;
return TRUE;
}
main函数
[cpp] view plain copy
#include stdio.h
#include stdlib.h
#include time.h
#include "sll_node.h"
int insertNode(Node **rootp, int newValue);
int insertNode2(Node **nextp, int newValue);
int main()
{
srand(time(0));
Node *head = (Node *)malloc(sizeof(Node));
【c语言链表插入节点函数 c语言链表节点是什么】head-next = NULL;
for (int i = 0; i5; i++)
{
int temp = rand() % 50;
printf("%d\n", temp);
//insertNode(head,temp);
insertNode2(head,temp);
}
Node *p = head-next;
while (p != NULL)
{
printf("%d\n", p-value);
p = p-next;
}
getchar();
getchar();
return 0;
}
关于c语言链表插入节点函数和c语言链表节点是什么的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
- mysql子查询和连接查询 mysql子查询插入
- 将数据保存到文件中c语言 将数据保存到mongodb
- 罗布人村天气 mysql语言具有的功能
- mysql 加速 mysql插入提速
- redis编程语言 redis对应c语言
- mongodbinsert mongodb快速插入大量数据
- redis一般和什么语言一起开发 和redis类似的编程
- mongodb采用什么语言 mongodb的设计采用什么
- c连接mysql数据库 c连接mysql报错
- mongodb底层数据结构 mongodb底层语言
