单链表及其相关函数
实现功能
BuySListNode ————————————申请一个新节点并赋值
SListLength —————————————计算链表的长度
SListPushBack————————————尾插
SListPushFront————————————头插
SListPopBack—————————————尾删
SListPopFront————————————头删
SListFindByVal————————————按值查找链表
SListFindByPos————————————按位置查找链表
SListInsertAfter————————————任意位置插入
SListEraseAfter————————————任意位置删除
SListPrint——————————————打印链表
SList.h
#pragma once#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>typedef int SLTDataType;typedef struct SLTNode
{SLTDataType data;struct SLTNode* next;
}SLTNode;//申请一个新节点并赋值
extern SLTNode* BuySListNode(SLTDataType x);//计算链表的长度
extern int SListLength(SLTNode* phead);//尾插
extern void SListPushBack(SLTNode** pphead, SLTDataType x);//头插
extern void SListPushFront(SLTNode** pphead, SLTDataType x);//尾删
extern void SListPopBack(SLTNode** pphead);//头删
extern void SListPopFront(SLTNode** pphead);//按值查找链表
extern SLTNode* FindByVal(SLTNode* phead, SLTDataType x);
extern void SListFindByVal(SLTNode* phead, SLTDataType x);//按位置查找链表
void FindByPos(SLTNode* phead, int pos, SLTNode** pp_aim1, int* p_aim2);
extern void SListFindByPos(SLTNode* phead, int pos);//任意位置插入
extern void SListInsertAfter(SLTNode** pphead, int pos, SLTDataType x);//任意位置删除
extern void SListEraseAfter(SLTNode** pphead, int pos);//打印链表
extern void SListPrint(SLTNode* phead);
SList.c
#include "SList.h"SLTNode* BuySListNode(SLTDataType x)
{SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));if (!newnode){perror("create newnode");exit(-1);}newnode->next = NULL;newnode->data = x;return newnode;
}int SListLength(SLTNode* phead)
{SLTNode* tail = phead;int count = 0;for (count = 1; tail->next != NULL; ++count){tail = tail->next;}return count;
}bool CheckEmpty(SLTNode* phead)
{return (phead) ? false : true;
}void SListPushBack(SLTNode** pphead, SLTDataType x)
{if (CheckEmpty(*pphead)){*pphead = BuySListNode(x);}else{SLTNode* tail = *pphead;while (tail->next){tail = tail->next;}tail->next = BuySListNode(x);}
}void SListPushFront(SLTNode** pphead, SLTDataType x)
{SLTNode* newnode = BuySListNode(x);newnode->next = *pphead;*pphead = newnode;
}void SListPopBack(SLTNode** pphead)
{if (CheckEmpty(*pphead)){printf("SList is empty!\n");return;}//注意仅存有一个节点的情况if (!(*pphead)->next){free(*pphead);*pphead = NULL;}//寻找前一个节点else{SLTNode* tail = *pphead;while (tail->next->next){tail = tail->next;}free(tail->next);tail->next = NULL;}
}void SListPopFront(SLTNode** pphead)
{if (CheckEmpty(*pphead)){printf("SList is empty!\n");return;}SLTNode* ret = *pphead;*pphead = (*pphead)->next;free(ret);
}SLTNode* FindByVal(SLTNode* phead, SLTDataType x)
{SLTNode* cur = phead;while (cur){if (cur->data == x){return cur;}elsecur = cur->next;}return NULL;
}
void SListFindByVal(SLTNode* phead, SLTDataType x)
{SLTNode* pos = FindByVal(phead, x);if (!pos){printf("Don't find it!\n");return;}//进行多次查找int i = 1;while (pos){printf("第%d个pos节点:%p->%d\n", i++, pos, pos->data);pos = FindByVal(pos->next, x);}
}void FindByPos(SLTNode* phead, int pos, SLTNode** pp_aim1, int* p_aim2)
{if (pos < 0 || pos > SListLength(phead)){printf("The position is illegal!\n");}else{SLTNode* tail = phead;//注意循环只需进行pos-1,所以使用--poswhile (--pos){tail = tail->next;}*pp_aim1 = tail;*p_aim2 = tail->data;}
}
void SListFindByPos(SLTNode* phead, int pos)
{SLTNode* aim1;int aim2 = 0;FindByPos(phead, pos, &aim1, &aim2);printf("%d号节点:%p->%d\n", pos, aim1, aim2);
}void SListInsertAfter(SLTNode** pphead, int pos, SLTDataType x)
{if (pos < 0 || pos > SListLength(*pphead)){printf("The position is illegal!\n");}else{if (*pphead == NULL){*pphead = BuySListNode(x);}else if ((*pphead)->next == NULL){(*pphead)->next = BuySListNode(x);}else{SLTNode* dest = *pphead;while (--pos){dest = dest->next;}SLTNode* newnode = BuySListNode(x);newnode->next = dest->next;dest->next = newnode;}}
}void SListEraseAfter(SLTNode** pphead, int pos)
{if (pos <= 0 || pos >= SListLength(*pphead)){printf("The position is illegal!\n");}else{SLTNode* prev = *pphead;while (--pos){prev = prev->next;}SLTNode* afet = prev->next->next;free(prev->next);prev->next = afet;}
}void SListPrint(SLTNode* phead)
{if (CheckEmpty(phead)){printf("SList is empty!\n");return;}SLTNode* tail = phead;while (!tail == NULL){printf("%d->", tail->data);tail = tail->next;}printf("NULL\n");
}
test.c
#include "SList.h"void test1()
{SLTNode* pList = NULL;SListPushFront(&pList, 2);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 5);SListPushFront(&pList, 1);SListPrint(pList);
}void test2()
{SLTNode* pList = NULL;SListPushFront(&pList, 2);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 5);SListPushFront(&pList, 1);SListPrint(pList);SListPopBack(&pList);SListPopBack(&pList);SListPopBack(&pList);SListPopBack(&pList);SListPopBack(&pList);SListPrint(pList);
}void test3()
{SLTNode* pList = NULL;SListPushFront(&pList, 2);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 5);SListPushFront(&pList, 1);SListPrint(pList);SListPopBack(&pList);SListPopBack(&pList);SListPopBack(&pList);SListPopBack(&pList);SListPopBack(&pList);SListPrint(pList);
}void test4()
{SLTNode* pList = NULL;SListPushFront(&pList, 2);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 5);SListPushFront(&pList, 1);SListPrint(pList);SListPopFront(&pList);SListPopFront(&pList);SListPopFront(&pList);SListPopFront(&pList);SListPrint(pList);SListPopFront(&pList);SListPrint(pList);
}void test5()
{SLTNode* pList = NULL;SListPushFront(&pList, 3);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 3);SListPushFront(&pList, 1);SListPrint(pList);SListFindByVal(pList, 3);
}void test6()
{SLTNode* pList = NULL;SListPushFront(&pList, 2);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 5);SListPushFront(&pList, 1);SListPrint(pList);SListFindByPos(pList, 5);}void test7()
{SLTNode* pList = NULL;SListPushFront(&pList, 1);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 5);SListPrint(pList);SListInsertAfter(&pList, 1, 2);SListPrint(pList);
}void test8()
{SLTNode* pList = NULL;SListPushFront(&pList, 2);SListPushBack(&pList, 3);SListPushBack(&pList, 4);SListPushBack(&pList, 5);SListPushFront(&pList, 1);SListPrint(pList);SListEraseAfter(&pList, 1);SListEraseAfter(&pList, 1);SListEraseAfter(&pList, 1);SListEraseAfter(&pList, 1);SListEraseAfter(&pList, 0);SListPrint(pList);
}void main()
{test1();printf("-------------------------------\n");test2();printf("-------------------------------\n");test3();printf("-------------------------------\n");test4();printf("-------------------------------\n");test5();printf("-------------------------------\n");test6();printf("-------------------------------\n");test7();printf("-------------------------------\n");test8();printf("-------------------------------\n");
}
相关文章:

单链表及其相关函数
实现功能BuySListNode ————————————申请一个新节点并赋值SListLength —————————————计算链表的长度SListPushBack————————————尾插SListPushFront————————————头插SListPopBack—————————————尾删SListPopFront—…...

Linux段错误调试
1、设置ulimit ulimit -a 查看 ulimit -c 2048 设置core大小 2、设置core文件信息 下面两个设置需要在root下设置,否则权限不通过 echo 1>/proc/sys/kernel/core_uses_pid echo "/tmp/corefile-%e-%p-%t" >/proc/sys/kernel/core_pattern 3、编译…...

Gopro卡无法打开视频恢复方法
下边来看一个文件系统严重受损的Gopro恢复案例故障存储: 120G SD卡故障现象:客户正常使用,备份数据时发现卡无法打开,多次插拔后故障依旧。故障分析:Winhex查看发现0号分区表扇区正常,这应该是一个exfat格式的文件系统,但是逻辑盘…...

vmware虚拟机与树莓派4B安装ubuntu1804 + ros遇到的问题
如题所示,本人在虚拟机上安装ubuntu1804,可以很容易安装,并且更换系统apt源和ros源,然后安装ros,非常顺利,但是在树莓派4B上安装raspiberry系统就遇到了好多问题。 树莓派我烧录的是这个镜像:ub…...

JS逆向hook通用脚本合集
1. cookie 通用hook Cookie Hook 用于定位 Cookie 中关键参数生成位置,以下代码演示了当 Cookie 中匹配到了 v 关键字, 则插入断点 (function () {var cookieTemp ;Object.defineproperty(document, cookie, {set: function (val) {if (val.indexOf(v…...

nacos的介绍和下载安装(详细)
目录 一、介绍 1.什么是nacos(含有官方文档)? 2.nacos的作用是什么? 3.什么是nacos注册中心? 4.核心功能 二、下载安装 一、介绍 1.什么是nacos(含有官方文档)? 一个更易于…...

【算法经典题集】前缀和与数学(持续更新~~~)
😽PREFACE🎁欢迎各位→点赞👍 收藏⭐ 评论📝📢系列专栏:算法经典题集🔊本专栏涉及到的知识点或者题目是算法专栏的补充与应用💪种一棵树最好是十年前其次是现在前缀和一维前缀和k倍…...

寻找时空中的引力波:科学家控制量子运动至量子基态
据英国每日邮报报道,时空织布里的涟漪或可以揭示宇宙在140亿年前是如何产生的,然而寻找这些名为“引力波”的涟漪却一直难以捉摸。现在美国科学家们声称他们发现了改善用于检测宇宙大爆炸的引力波的探测器的方法。 宇宙大爆炸残留的引力波 美国加州理…...

第六讲:ambari-web 模块二次开发
上述图片为 Ambari 部署及操作 hdp 集群相关的部分界面截图。这些页面如果想调整的话,比如汉化,二次开发等,则可以修改 ambari-web 模块的源码来实现。 一、介绍 ambari-web 模块涉及到的界面有: HDP 集群部署向导已安装服务的仪表板、配置界面等主机列表及详细信息告警列…...

echarts--提示框显示不全问题记录
最近接手一个同事之前做的网页,发现里面使用echarts来绘制各类图表;有2个问题一个是提示框显示不全,另一个就是绘制总是有部分数据显示不全。后者就是div宽度问题。。。无语,说下前面一个问题吧,记录一下。 tooltip组…...

LeetCode 1653. 使字符串平衡的最少删除次数
LeetCode 1653. 使字符串平衡的最少删除次数 难度:middle\color{orange}{middle}middle Rating:1794\color{orange}{1794}1794 题目描述 给你一个字符串 sss ,它仅包含字符 ′a′a′a′ 和 ′b′b′b′ 。 你可以删除 sss 中任意…...

聊一聊代码重构——程序方法和类上的代码实践
使用工厂方法取代构造方法 构造方法的问题 我们使用构造方法来初始化对象时候,我们得到的只能是当前对象。而使用工厂方法替换构造方法,我们可以返回其子类型或者代理类型。这让我们可以通过不同的实现类来进行逻辑实现的变化。 更重要的一点是&#…...

嵌入式学习笔记——寄存器开发STM32 GPIO口
寄存器开发STM32GPIO口前言认识GPIOGPIO是什么GPIO有什么用GPIO怎么用STM32上GPIO的命名以及数量GPIO口的框图(重点)输入框图解析三种输入模式GPIO输入时内部器件及其作用1.保护二极管2.上下拉电阻(可配置)3.施密特触发器4.输入数…...

[ 攻防演练演示篇 ] 利用通达OA 文件上传漏洞上传webshell获取主机权限
🍬 博主介绍 👨🎓 博主介绍:大家好,我是 _PowerShell ,很高兴认识大家~ ✨主攻领域:【渗透领域】【数据通信】 【通讯安全】 【web安全】【面试分析】 🎉点赞➕评论➕收藏 养成习…...

程序设计与 C 语言期末复习
程序设计与 C 语言 1.计算机语言与编译 机器语言:一串仅由 0 和 1 序列表示的语言。计算机只能识别和接受 0 和 1 组成的指令。 符号语言(汇编语言):用一些英文字母和数字表示一个指令。 符号语言(汇编语言…...

05-思维导图Xmind快速入门
文章目录5.1 认识思维导图5.2 Xmind的主要结构及主题元素5.2.1 Xmind的多种结构5.2.2 主题分类5.2.3 Xmind的主题元素章节总结5.1 认识思维导图 什么是思维导图? 思维导图是一种将思维进行可视化的实用工具。 具体实现方法是用一个关键词去引发相关想法࿰…...

使用去中心化存储构建网站
今天的大多数网站都遵循后端服务器到前端代码的架构。但在 Web3 应用程序中,前端代码不具有与受智能合约保护的后端代码相同的去中心化性和弹性。那么如何使网站像智能合约一样具有弹性呢? 该体系结构似乎很简单: 创建一个没有服务器的静态…...

L - Let‘s Swap(哈希 + 规律)
2023河南省赛组队训练赛(四) - Virtual Judge (vjudge.net) 约瑟夫最近开发了一款名为Pandote的编辑软件,现在他正在测试,以确保它能正常工作,否则,他可能会被解雇!Joseph通过实现对Pandote上字符串的复制和…...

c语言自动内存回收(RAII实现)
简述 什么是RAII RAII(Resource Acquisition Is Initialization)是c之父Bjarne Stroustrup提出的概念。资源一般分三个步骤:获取、使用和销毁,而在自由使用内存的c语言中,资源的销毁常常是程序员容易遗漏的事情&…...

Node.js的简单学习一-----未完待续
文章目录前言学习目标一、初识Node.js1.1 回顾与思考1.1.1 需要掌握那些技术1.1.2 浏览器中的JavaScript的组成部分1.2 Node.js简介1 什么是Node.js2 Node.js中的JavaScript运行环境3 Node.js 可以做什么1.3 Node.js环境的安装1.4 在Node.js环境中执行JavaScript 代码终端中的快…...

linux入门---粘滞位
为什么会有粘滞位 一台服务器有很多人使用,每个人在机器上都会有一个家目录,在家目录里可以实现自己想要的操作,但是有时候我们需要一个公共路径来完成一些操作,比如说资料分享产生临时文件的增删查改等等,这就好比我…...

关于正则表达式的讲解
以下内容源于《linux命令行与shell脚本编程大全【第三版】》一书的整理。 在shell脚本中成功运用sed编辑器和gawk程序的关键,在于熟练地使用正则表达式。 一、正则表达式的简介 1、正则表达式的定义 正则表达式(regular expression)是一个…...

贝塞尔曲线与B样条曲线
文章目录0.参考1.问题起源与插值法的曲线拟合1.1.问题起源1.2.拉格朗日插值1.3.“基”的概念1.4.插值存在的Runge现象2.贝塞尔曲线2.1.控制点的思想2.2.由控制点生成贝塞尔曲线2.3.多个控制点时的贝塞尔曲线公式2.4.贝塞尔曲线的递推公式2.5.贝塞尔曲线的性质3.B样条曲线3.1.B样…...

C语言-基础了解-24-C头文件
C头文件 一、C 头文件 头文件是扩展名为 .h 的文件,包含了 C 函数声明和宏定义,被多个源文件中引用共享。有两种类型的头文件:程序员编写的头文件和编译器自带的头文件。 在程序中要使用头文件,需要使用 C 预处理指令 #include…...

The 19th Zhejiang Provincial Collegiate Programming Contest vp
和队友冲了这场,极限6题,重罚时铁首怎么说,前面的A题我贡献了太多的罚时,然后我的G题最短路调了一万年,因为太久没写了,甚至把队列打成了优先队列,没把head数组清空完全,都是我的锅呜…...

用于<分类>的卷积神经网络、样本不平衡问题的解决
输入图像——卷积层——池化层——全连接层——输出 卷积层:核心,用来提取特征。 池化层:对特征降维。实际的主要作用是下采样,减少参数量来提高计算速度。 卷积神经网络的训练:前向传播(分类识别…...

网上订餐管理系统的设计与实现
技术:Java、JSP等摘要:随着信息技术的广泛使用,电子商务对于提高管理和服务水平发挥着关键的作用。越来越多的商家开始着手于电子商务建设。电子商务的发展为人们的生活提供了极大的便利,也成为现实社会到网络社会的真实体现。当今…...

Httpclient测试
在IDEA中有一个非常方便的http接口测试工具httpclient,下边介绍它的使用方法,后边我们会用它进行接口测试。如果IDEA版本较低没有自带httpclient,需要安装httpclient插件1.插件2.controller进入controller类,找到http接口对应的方…...

EXCEL里的各种奇怪计算问题:数字后面自动多了 0.0001, 数字后面位数变成000,以及一些取整,数学函数
1 公式计算后的数,用只粘贴数值后,后面自动多了 0.0001,导致不再是整数的问题 问题入戏 见第1个8400,计算时就出现了问题,按正常,这里8400应该是整数,而不应该带小数,但是确实就计…...

PHP CRUL请求GET、POST
// GET请求 public function curlGet($url,$header){ $ch curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_s…...