嵌入式3-14

1、整理思维导图

2、重写链表的代码

3、实现链表,按值查找返回位置的功能,按位置查找返回值,释放单链表,链表逆置

node_p create_link_list()//创建头结点
{
node_p p=(node_p)malloc(sizeof(node));
if(p==NULL)
{
printf("空间申请失败\n");
return NULL;
}
p->len=0;
p->next==NULL;
printf("申请成功\n");
return p;
}
node_p create_node(datatype data)//申请新节点
{
node_p p=(node_p)malloc(sizeof(node));
if(p==NULL)
{
printf("空间申请失败\n");
return NULL;
}
p->data=data;
p->next=NULL;
return p;
}
int insert_head(node_p p,datatype data)//头插
{
if(p==NULL)
{
printf("链表不合法\n");
return 0;
}
node_p q=create_node(data);
if(q==NULL)
{
printf("空间申请失败\n");
return 0;
}
q->next=p->next;
p->next=q;
p->len++;
return 1;
}
int empty_link(node_p p)//判空
{
if(p==NULL)
{
printf("链表不合法\n");
return -1;
}
return p->next==NULL?1:0;
}
void dele_head(node_p p)//头删
{
if(p==NULL)
{
printf("链表不合法\n");
return;
}
if(empty_link(p))
return;
node_p q=p->next;
p->next=q->next;
free(q);
q=NULL;
p->len--;
}
void show_link(node_p p)//输出
{
if(p==NULL||p->len==0)
{
printf("错误\n");
return;
}
node_p q=p->next;
while(q!=NULL)
{
printf("%d->",q->data);
q=q->next;
}
puts("NULL");
}
void insert_tail(node_p p,datatype data)//尾插
{
if(p==NULL)
{
return;
}
node_p q=p->next;
while(q->next!=NULL)
{
q=q->next;
}
q->next=create_node(data);
q->next->next=NULL;
p->len++;
}
void dele_tail(node_p p)//尾删
{
if(p==NULL)
{
return;
}
node_p q=p->next;
while(q->next->next!=NULL)
{
q=q->next;
}
free(q->next);
q->next=NULL;
p->len--;
}
void insert_pos(node_p p,datatype data,int pos)//插入
{
if(p==NULL)
return;
node_p q=p;
while(pos)
{
q=q->next;
pos--;
}
node_p r=create_node(data);
if(r==NULL)
return;
r->next=q->next;
q->next=r;
p->len++;
}
void dele_pos(node_p p,int pos)//删除
{
if(p==NULL)
return;
node_p q=p;
for(int i=0;i<pos;i++)
{
q=q->next;
}
node_p del=q->next;
q->next=q->next->next;
free(del);
del=NULL;
p->len--;
}

相关推荐
电鱼智能的电小鱼3 小时前
基于电鱼 AI 工控机的智慧工地视频智能分析方案——边缘端AI检测,实现无人值守下的实时安全预警
网络·人工智能·嵌入式硬件·算法·安全·音视频
孫治AllenSun3 小时前
【算法】图相关算法和递归
windows·python·算法
格图素书4 小时前
数学建模算法案例精讲500篇-【数学建模】DBSCAN聚类算法
算法·数据挖掘·聚类
yuuki2332335 小时前
【数据结构】用顺序表实现通讯录
c语言·数据结构·后端
DashVector5 小时前
向量检索服务 DashVector产品计费
数据库·数据仓库·人工智能·算法·向量检索
AI纪元故事会5 小时前
【计算机视觉目标检测算法对比:R-CNN、YOLO与SSD全面解析】
人工智能·算法·目标检测·计算机视觉
夏鹏今天学习了吗5 小时前
【LeetCode热题100(59/100)】分割回文串
算法·leetcode·深度优先
卡提西亚5 小时前
C++笔记-10-循环语句
c++·笔记·算法
还是码字踏实5 小时前
基础数据结构之数组的双指针技巧之对撞指针(两端向中间):三数之和(LeetCode 15 中等题)
数据结构·算法·leetcode·双指针·对撞指针
Coovally AI模型快速验证8 小时前
当视觉语言模型接收到相互矛盾的信息时,它会相信哪个信号?
人工智能·深度学习·算法·机器学习·目标跟踪·语言模型