数据结构链表操作
#include list.h //创建链表 node_p create_link_list() { node_p H (node_p)malloc(sizeof(node)); if(HNULL) { printf(空间申请失败\n); return NULL; } H-len0; H-nextNULL; return H; } //创建一个新节点 node_p create_new_point(datatype data) { node_p new(node_p)malloc(sizeof(node)); if(newNULL) { printf(空间申请失败\n); return NULL; } new-datadata; return new; } //头插 void insert_head(node_p H,datatype data) { if(HNULL) { printf(入参为空请检查\n); return; } node_p newcreate_new_point(data); new-nextH-next; H-nextnew; H-len; } //判空 int empty(node_p H) { if(HNULL) { printf(参数列表为空\n); return -1; } return H-nextNULL?1:0; } //输出 void show(node_p H) { if(HNULL) { printf(入参为空请检查\n); return; } if(empty(H)) { printf(参数列表为空\n); return; } node_p pH-next; while(p!NULL) { printf(%d-,p-data); pp-next; } printf(NULL\n); } //头删 void dele_head(node_p H) { if(HNULL) { printf(入参为空请检查\n); return; } if(empty(H)) { printf(参数列表为空\n); return; } node_p deleH-next; H-nextdele-next; free(dele); H-len--; } //尾插 void insert_tail(node_p H,datatype data) { if(HNULL) { printf(入参为空请检查\n); return; } node_p pH-next; while(p-next!NULL) { pp-next; } node_p newcreate_new_point(data); p-nextnew; new-nextNULL; H-len; } //尾删 void dele_tail(node_p H) { if(HNULL) { printf(入参为空请检查\n); return; } if(empty(H)) { printf(参数列表为空\n); return; } node_p pH;//从头结点开始 while(p-next-next!NULL) { pp-next; } node_p delep-next; p-nextNULL; free(dele); H-len--; } //按位置插入 void insert_pos(node_p H,int pos,datatype data) { if(HNULL) { printf(入参为空请检查\n); return; } if(pos1 || posH-len1) { printf(位置不合理\n); return; } node_p pH; for(int i0;ipos-1;i) { pp-next; } node_p newcreate_new_point(data); new-nextp-next; p-nextnew; H-len; } //按位置删除 void dele_pos(node_p H,int pos) { if(HNULL) { printf(入参为空请检查\n); return; } if(empty(H)) { printf(参数列表为空\n); return; } if(pos1 || posH-len1) { printf(位置不合理\n); return; } node_p pH; for(int i0;ipos-1;i) { pp-next; } node_p delep-next; p-nextdele-next; free(dele); H-len--; } //按位置修改 void change_pos_v(node_p H,int pos,datatype data) { if(HNULL) { printf(入参为空请检查\n); return; } if(empty(H)) { printf(参数列表为空\n); return; } if(pos1 || posH-len1) { printf(位置不合理\n); return; } node_p pH; for(int i0;ipos;i) { pp-next; } p-datadata; } //按位置查找返回值 int pos_value(node_p H,int pos) { if(HNULL) { printf(入参为空请检查\n); return -1; } if(empty(H)) { printf(参数列表为空\n); return -2; } if(pos1 || posH-len1) { printf(位置不合理\n); return -3; } node_p pH; for(int i0;ipos;i) { pp-next; } return p-data; } //按值查找返回位置 int value_pos(node_p H,datatype data) { if(HNULL) { printf(入参为空请检查\n); return -1; } if(empty(H)) { printf(参数列表为空\n); return -2; } node_p pH; for(int i1;p!NULL;i) { pp-next; if(p-datadata) return i; } } //链表逆置 #if 0 void inver_link_list(node_p H) { if(HNULL) { printf(入参为空请检查\n); return; } if(empty(H)) { printf(参数列表为空\n); return; } node_p pH-next-next; H-next-nextNULL; node_p np-next; while(p!NULL) { p-nextH-next; H-nextp; pn; if(n!NULL) { n-next; } } } //释放 void free_list(node_p H) { if(HNULL) { printf(入参为空请检查\n); return; } if(empty(H)) { printf(参数列表为空\n); return; } node_p pH-next; while(p!NULL) { pp-next; free(p); } } #endif#ifndef __LIST_H__ #define __LIST_H__ #include stdio.h #include string.h #include stdlib.h typedef int datatype; typedef struct node { union { datatype data; int len; }; struct node* next; }node,*node_p; node_p create_link_list(); node_p create_new_point(datatype data); void insert_head(node_p H,datatype data); int empty(node_p H); void show(node_p H); void dele_head(node_p H); void insert_tail(node_p H,datatype data); void dele_tail(node_p); void insert_pos(node_p,int pos,datatype data); void dele_pos(node_p,int pos); void change_pos_v(node_p H,int pos,datatype data); int pos_value(node_p H,int pos); int value_pos(node_p H,datatype data); void free_list(node_p H); void inver_link_list(node_p H); #endif#include list.h int main(int argc, const char *argv[]) { node_p Hcreate_link_list(); insert_head(H,20); insert_head(H,30); insert_head(H,40); insert_head(H,50); insert_head(H,60); insert_head(H,70); insert_head(H,80); insert_head(H,90); show(H); printf(--------\n); dele_head(H); dele_head(H); show(H); printf(--------\n); insert_tail(H,100); insert_tail(H,200); show(H); printf(--------\n); dele_tail(H); dele_tail(H); show(H); printf(--------\n); insert_pos(H,3,999); insert_pos(H,4,888); show(H); printf(--------\n); dele_pos(H,2); dele_pos(H,3); show(H); printf(--------\n); change_pos_v(H,2,333); show(H); printf(--------\n); int rec_valpos_value(H,2); printf(rec_val%d\n,rec_val); int posvalue_pos(H,20); printf(pos%d\n,pos); printf(--------\n); // inver_link_list(H); // show(H); // printf(--------\n); // free_list(H); // HNULL; return 0; }

相关新闻

(8-2)Bellman-Ford算法的局限性与改进

(8-2)Bellman-Ford算法的局限性与改进

Bellman-Ford算法的局限性与改进

2026/7/10 13:45:25 阅读更多 →
Obsidian表格插件终极指南:5个技巧实现笔记数据管理革命

Obsidian表格插件终极指南:5个技巧实现笔记数据管理革命

Obsidian表格插件终极指南:5个技巧实现笔记数据管理革命 【免费下载链接】obsidian-excel 项目地址: https://gitcode.com/gh_mirrors/ob/obsidian-excel 在知识管理领域,Obsidian表格插件正在彻底改变我们处理结构化数据的方式。这款强大的工具…

2026/7/10 13:43:24 阅读更多 →
Android Studio中文语言包终极指南:3分钟打造全中文开发环境

Android Studio中文语言包终极指南:3分钟打造全中文开发环境

Android Studio中文语言包终极指南:3分钟打造全中文开发环境 【免费下载链接】AndroidStudioChineseLanguagePack AndroidStudio中文插件(官方修改版本) 项目地址: https://gitcode.com/gh_mirrors/an/AndroidStudioChineseLanguagePack 你是否曾…

2026/7/10 13:41:20 阅读更多 →

最新新闻

告别限速烦恼:LinkSwift网盘直链下载助手,你的高效下载新伙伴

告别限速烦恼:LinkSwift网盘直链下载助手,你的高效下载新伙伴

告别限速烦恼:LinkSwift网盘直链下载助手,你的高效下载新伙伴 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 ,支持 百度网盘 / 阿里云盘 / 中…

2026/7/10 14:33:37 阅读更多 →
Astroluma:终极自托管家庭实验室仪表板 - 一站式管理您的数字生活

Astroluma:终极自托管家庭实验室仪表板 - 一站式管理您的数字生活

Astroluma:终极自托管家庭实验室仪表板 - 一站式管理您的数字生活 【免费下载链接】Astroluma Astroluma is a feature-rich, user-friendly dashboard designed to help you manage multiple aspects of your daily tasks and services. 项目地址: https://gitc…

2026/7/10 14:33:37 阅读更多 →
终极指南:NeverSink流放之路2物品过滤器完整使用教程

终极指南:NeverSink流放之路2物品过滤器完整使用教程

终极指南:NeverSink流放之路2物品过滤器完整使用教程 【免费下载链接】NeverSink-Filter-for-PoE2 This is a lootfilter for the game "Path of Exile 2". It adds colors, sounds, map icons, beams to highlight remarkable gear and inform the user …

2026/7/10 14:33:37 阅读更多 →
如何在Windows 10/11上完美运行Android应用:WSABuilds终极指南

如何在Windows 10/11上完美运行Android应用:WSABuilds终极指南

如何在Windows 10/11上完美运行Android应用:WSABuilds终极指南 【免费下载链接】WSABuilds Run Windows Subsystem For Android on your Windows 10 and Windows 11 PC using prebuilt binaries with Google Play Store (MindTheGapps) and/or Magisk or KernelSU (…

2026/7/10 14:25:34 阅读更多 →
TMC7300与STM32L011K4驱动有刷直流电机方案详解

TMC7300与STM32L011K4驱动有刷直流电机方案详解

1. TMC7300与STM32L011K4组合方案概述 在小型嵌入式系统中驱动有刷直流电机时,工程师常面临功率密度、控制精度和能耗的平衡难题。TMC7300作为Trinamic推出的高集成度电机驱动芯片,与超低功耗的STM32L011K4微控制器组合,为解决这一问题提供了…

2026/7/10 14:09:57 阅读更多 →
AI Agent入门指南:从ReAct到Multi-Agent协作

AI Agent入门指南:从ReAct到Multi-Agent协作

文章目录什么是AI Agent?一、ReAct(推理行动)模式二、工具调用(Function Calling)三、主流框架对比四、记忆系统总结开发调试技巧什么是AI Agent? AI Agent能自主感知环境、制定计划、执行行动。具备自主性…

2026/7/10 14:09:57 阅读更多 →

日新闻

STM32与LTC1864高精度ADC的SPI通信实现

STM32与LTC1864高精度ADC的SPI通信实现

1. 项目背景与核心需求在工业控制和嵌入式系统开发中,模拟信号与数字系统的无缝集成一直是工程师面临的关键挑战。LTC1864作为一款16位高精度ADC转换器,配合STM32F101ZG这类主流微控制器,能够构建高性能的模拟信号采集系统。这种组合特别适合…

2026/7/10 0:03:07 阅读更多 →
猫抓插件:浏览器资源嗅探与视频下载的终极解决方案

猫抓插件:浏览器资源嗅探与视频下载的终极解决方案

猫抓插件:浏览器资源嗅探与视频下载的终极解决方案 【免费下载链接】cat-catch 猫抓 浏览器资源嗅探扩展 / cat-catch Browser Resource Sniffing Extension 项目地址: https://gitcode.com/GitHub_Trending/ca/cat-catch 还在为网页视频无法下载而烦恼吗&am…

2026/7/10 0:05:09 阅读更多 →
直流有刷电机驱动方案:TC78H653FTG与MKV46F256VLH16应用

直流有刷电机驱动方案:TC78H653FTG与MKV46F256VLH16应用

1. 直流有刷电机驱动方案概述在工业自动化和消费电子领域,直流有刷电机因其结构简单、控制方便、成本低廉等优势,仍然是许多应用场景的首选驱动方案。TC78H653FTG作为东芝推出的新一代H桥驱动器,与MKV46F256VLH16微控制器配合使用&#xff0c…

2026/7/10 0:05:09 阅读更多 →

周新闻

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容 【免费下载链接】BiliTools A cross-platform bilibili toolbox. 跨平台哔哩哔哩工具箱,支持下载视频、番剧等等各类资源 项目地址: https://gitcode.com/GitHub_Trending/bilit/BiliTools …

2026/7/8 16:14:06 阅读更多 →
威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型的陌生现状在忙碌疲惫的一天里,参与了关于混合后量子密码学的讨论,应付端点攻击找茬的人,还参与留言板讨论后,发现“威胁模型”对多数人仍是陌生概念,且多被当作时髦用语。有趣的相关画作有一幅由 Embyr 创作的…

2026/7/9 13:46:46 阅读更多 →
渗透测试入门指南:从零基础到实战环境搭建

渗透测试入门指南:从零基础到实战环境搭建

1. 从“看热闹”到“入门”:我理解的渗透测试到底是什么?每次看到新闻里说某个大公司的数据被“黑”了,或者某个网站被攻击导致服务瘫痪,你是不是和我一样,心里会冒出两个念头:一是“这黑客真厉害”&#x…

2026/7/9 21:41:05 阅读更多 →

月新闻