C语言的链表的相关操作
本变博客源于自己想复习一下C语言,所以便自己动手复习了一下链表的相关操作。做个人记录使用。
main.c
#include <stdio.h>
#include "list.h"int main()
{student *a;printf("hello world\n") ;printf("----初始化列表----------\n");a=init();printf("----创建列表----------\n");create_front_list(a,3);printf("list的个数为:count= %d\n",count);printf("----读取列表3位置上数据----------\n");read_any_list(a,3);printf("------------读取全部数据------------------\n");read_all_list(a);printf("----------插入列表,插入到位4的后面--------------------\n");insert_behind_list(a ,4);printf("----------插完后的列表数据---------\n");read_all_list(a);printf("------------删除列表指定位置的数据-------------------\n");delete_list(a,2);printf("-------------删除后列表的数据------------------\n");read_all_list(a);return 0;
}
list.c
#include<stdio.h>
#include <stdlib.h>
#include "list.h"
int count = 0;
student *init()
{//chuangjian节点student * head=(struct student *)malloc(sizeof(student));if(head==NULL){printf("n=malloc failed \n");return NULL;}head->num=0;head->score=99.2;head->next=NULL;count++;return head;}//链表的建立
void create_front_list(student *head,int n)
{ int i;student * last;student * s;last=head;s=head;printf("请你输入%d个整数\n",n);for(i=0;i<n;i++){printf("begin to input\n");s->next=(struct student *)malloc(sizeof(student));last=s->next;s=last;scanf("%d,%f",&(s->num),&(s->score));printf("end to input\n");count++;}s->next=NULL;last=NULL;s=NULL;return ;
}//链表的读取操作
void read_all_list(student * head)
{int i;printf("total data in list is \n");student *re=head;if(head==NULL){printf("NO data\n");return ;}else{for(i=0;i<count;i++){printf("num = %d score= %f \n",re->num, re->score);re=re->next;}}}//读取其中指定第几个节点的数值
void read_any_list(student * head,int n)
{ int i=1;student *re=head;printf("That you want to read list sequence is %d\n",n);if(n>count){printf("The number you have input exceeds the max length of this list \n ");return ;}else{while(true){re=re->next;i++;if(i==n){printf("the number has been find ,data as follow \n");printf("num= %d, score= %f\n",re->num,re->score);break;}}return ;}}//链表的插入//由于是单链表所以我这里只使用尾部
void insert_behind_list(student * head ,int n)
{printf("insert behind list \n\n");int i;student * s=head;if(n>count){//表名插入的位置已经查过了节点长度printf("you has exceed this max length\n");return ;}else{ //开辟一个新的节点student * last=(struct student *)malloc(sizeof(student));printf("please input your inserted data \n");scanf("%d,%f",&(last->num),&(last->score));for(i=1;i<n;i++){s=s->next;//借助一个指针指向你想插入的节点前面}last->next=s->next;s->next=last;last=NULL;printf("---------end of insert data--------\n");count++;}}//链表的删除
void delete_list(student * head,int n)
{int i;student * s=head;student * q=head->next;printf("the number do you want to delete is number %d",n);if(n>count){printf("there are no data \n");}else{for(i=1;i<n;i++){s=s->next;q=q->next;}printf("你想删除的数据是:%d,%f",q->num,q->score);s->next=q->next;free(q);count--;//记录节点的个数的}}
list.h
#define true 1
#define flase 0typedef struct student{int num;float score;struct student *next ;}student;
extern int count;
student *init();
void create_front_list(student *head,int n);
void read_all_list(student * head);
void read_any_list(student * head,int n);
void insert_behind_list(student * head ,int n);
void delete_list(student * head,int n);
备注:每次更改操作后必须使用count–,否则内存就会出现泄漏。
hello world
----初始化列表----------
----创建列表----------
请你输入3个整数
begin to input
1,1
end to input
begin to input
2,2
end to input
begin to input
3,3
end to input
list的个数为:count= 4
----读取列表3位置上数据----------
That you want to read list sequence is 3
the number has been find ,data as follow
num= 2, score= 2.000000
------------读取全部数据------------------
total data in list is
num = 0 score= 99.199997
num = 1 score= 1.000000
num = 2 score= 2.000000
num = 3 score= 3.000000
----------插入列表,插入到位4的后面--------------------
insert behind list
please input your inserted data
4,4
---------end of insert data--------
----------插完后的列表数据---------
total data in list is
num = 0 score= 99.199997
num = 1 score= 1.000000
num = 2 score= 2.000000
num = 3 score= 3.000000
num = 4 score= 4.000000
------------删除列表指定位置的数据-------------------
the number do you want to delete is number 2你想删除的数据是:2,2.000000-------------删除后列表的数据------------------
total data in list is
num = 0 score= 99.199997
num = 1 score= 1.000000
num = 3 score= 3.000000
num = 4 score= 4.000000
Process returned 0 (0x0) execution time : 27.276 s
Press any key to continue.

相关文章:
C语言的链表的相关操作
本变博客源于自己想复习一下C语言,所以便自己动手复习了一下链表的相关操作。做个人记录使用。 main.c #include <stdio.h> #include "list.h"int main() {student *a;printf("hello world\n") ;printf("----初始化列表----------\…...
Python3中typing模块
Python类型注解是Python 3.5版本之后引入的新特性,它可以让开发者在函数、变量等声明时为其指定类型。typing模型能够声明类型,防止运行时出现参数和返回值类型不符合的问题。 ### 1. 基本类型注解 def hello(name: str) -> str:return (Hello, na…...
C语言自动抓取淘宝商品详情网页数据,实现轻松高效爬虫
你是否曾经遇到过需要大量获取网页上的数据,但手动复制粘贴又太过费时费力?那么这篇文章就是为你而写。今天我们将会详细讨论如何使用C语言实现自动抓取网页上的数据。本文将会从以下8个方面进行逐步分析讨论。 1. HTTP协议的基本原理 在开始之前&…...
数据结构---跳表
目录标题 为什么会有跳表跳表的原理跳表的模拟实现准备工作find函数insert函数erase函数 测试效率比较 为什么会有跳表 在前面的学习过程中我们学习过链表这个容器,这个容器在头部和尾部插入数据的时间复杂度为O(1),但是该容器存在一个缺陷就是不管数据…...
为什么Tomcat的NIO在读取body时要模拟阻塞?
文章首发地址 Tomcat的NIO完全可以以非阻塞方式处理IO,为什么在读取body部分时要模拟阻塞呢?在Tomcat的NIO读取HTTP请求时,为了保证请求的正确性和可靠性,需要模拟阻塞模式,这是因为servlet规范里定义了ServletInputSt…...
26 | 谷歌应用APP数据分析
基于kaggle公开数据集,对谷歌应用市场的APP情况进行数据探索和分析。 from kaggle: https://www.kaggle.com/lava18/google-play-store-apps 分析思路: 0、数据准备 1、数据概览 2、种类对Rating的影响 3、定价策略 4、因素相关性分析 5、用户评价 6、总结 0、数据准备 (…...
BFS 五香豆腐
题目描述 经过谢老师n次的教导,dfc终于觉悟了——过于腐败是不对的。但是dfc自身却无法改变自己,于是他找到了你,请求你的帮助。 dfc的内心可以看成是5*5个分区组成,每个分区都可以决定的的去向,0表示继续爱好腐败&…...
opencv实战项目 手势识别-手势控制键盘
手势识别是一种人机交互技术,通过识别人的手势动作,从而实现对计算机、智能手机、智能电视等设备的操作和控制。 1. opencv实现手部追踪(定位手部关键点) 2.opencv实战项目 实现手势跟踪并返回位置信息(封装调用&am…...
1.作用域
1.1局部作用域 局部作用域分为函数作用域和块作用域。 1.函数作用域: 在函数内部声明的变量只能在函数内部被访问,外部无法直接访问。 总结: (1)函数内部声明的变量,在函数外部无法被访问 (2)函数的参数也是函数内部的局部变量 (3)不同函数…...
黑马B站八股文学习笔记
视频地址:https://www.yuque.com/linxun-bpyj0/linxun/vy91es9lyg7kbfnr 大纲 基础篇 基础篇要点:算法、数据结构、基础设计模式 1. 二分查找 要求 能够用自己语言描述二分查找算法能够手写二分查找代码能够解答一些变化后的考法 算法描述 前提&a…...
前端常用的上传下载文件的几种方式,直接上传、下载文件,读取.xlsx文件数据,导出.xlsx数据
一、通过调用接口下载文件 const onExport async () > {try {let res await axios.request({method: POST,url: 请求地址,responseType: blob,params: { data: null },headers: { Authorization: Bearer UserModule.token },//看看请求是否需要token});let reader new…...
FPGA应用学习笔记--时钟域的控制 亚稳态的解决
时钟域就是同一个时钟的区域,体现在laways语句边缘触发语句中,设计规模增大就会导致时钟不同步,有时差,就要设计多时钟域。 会经过与门的延时产生的新时钟域,这种其实不推荐使用,但在ascl里面很常见 在处理…...
AirServer是什么软件,手机屏幕投屏电脑神器
什么是 AirServer? AirServer 是适用于 Mac 和 PC 的先进的屏幕镜像接收器。 它允许您接收 AirPlay 和 Google Cast 流,类似于 Apple TV 或 Chromecast 设备。AirServer 可以将一个简单的大屏幕或投影仪变成一个通用的屏幕镜像接收器 ,是一款…...
如何使用 AT+WEBSERVER 指令实现自定义的 Webserver html 网页配网
开启 AT 固件中的 Webserver 指令和 FS 指令支持 乐鑫官网发布的默认通用 AT 固件不支持 webserver 配网功能, 需要用户自己搭建 esp-at 环境,并在 sdkconfig 中开启 webserver AT 指令 和 FS 指令的支持, 如下图所示: 测试 AT 固…...
期权定价模型系列【4】—期权组合的Delta-Gamma-Vega中性
期权组合的Delta-Gamma-Vega中性 期权组合构建时往往会进行delta中性对冲,在进行中性对冲后,期权组合的delta敞口为0,此时期权组合仍然存在gamma与vega敞口。因此研究期权组合的delta-gamma-vega敞口中性是有必要的。 本文旨在对delta-gamma-…...
k8sday02
第四章 实战入门 本章节将介绍如何在kubernetes集群中部署一个nginx服务,并且能够对其进行访问。 Namespace Namespace是kubernetes系统中的一种非常重要资源,它的主要作用是用来实现多套环境的资源隔离或者多租户的资源隔离。 默认情况下&…...
黑马头条项目学习--Day2: app端文章查看,静态化freemarker,分布式文件系统minIO
app端文章 Day02: app端文章查看,静态化freemarker,分布式文件系统minIOa. app端文章列表查询1) 需求分析2) 实现思路 b. app端文章详细1) 需求分析2) Freemarker概述a) 基础语法种类b) 集合指令(List和Map)c) if指令d) 运算符e) 空值处理f) …...
特语云用Linux和MCSM面板搭建 我的世界基岩版插件服 教程
Linux系统 用MCSM和DockerWine 搭建 我的世界 LiteLoaderBDS 服务器 Minecraft Bedrock Edition 也就是我的世界基岩版,这是 Minecraft 的另一个版本。Minecraft 基岩版可以运行在 Win10、Android、iOS、XBox、switch。基岩版不能使用 Java 版的服务器,…...
2023.8
编译 make install 去掉 folly armv8-acrc arrow NEON 相关链接 https://blog.csdn.net/u011889952/article/details/118762819 这里面的方案二,我之前也是用的这个 https://blog.csdn.net/zzhongcy/article/details/105512565 参考的此博客 火焰图 https://b…...
CSV文件编辑器——Modern CSV for mac
Modern CSV for Mac是一款功能强大、操作简单的CSV文件编辑器,适用于Mac用户快速、高效地处理和管理CSV文件。Modern CSV具有直观的用户界面,可以轻松导入、编辑和导出CSV文件。它支持各种功能,包括排序、过滤、查找和替换,使您能…...
XCTF-web-easyupload
试了试php,php7,pht,phtml等,都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接,得到flag...
【Python】 -- 趣味代码 - 小恐龙游戏
文章目录 文章目录 00 小恐龙游戏程序设计框架代码结构和功能游戏流程总结01 小恐龙游戏程序设计02 百度网盘地址00 小恐龙游戏程序设计框架 这段代码是一个基于 Pygame 的简易跑酷游戏的完整实现,玩家控制一个角色(龙)躲避障碍物(仙人掌和乌鸦)。以下是代码的详细介绍:…...
多场景 OkHttpClient 管理器 - Android 网络通信解决方案
下面是一个完整的 Android 实现,展示如何创建和管理多个 OkHttpClient 实例,分别用于长连接、普通 HTTP 请求和文件下载场景。 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas…...
visual studio 2022更改主题为深色
visual studio 2022更改主题为深色 点击visual studio 上方的 工具-> 选项 在选项窗口中,选择 环境 -> 常规 ,将其中的颜色主题改成深色 点击确定,更改完成...
3403. 从盒子中找出字典序最大的字符串 I
3403. 从盒子中找出字典序最大的字符串 I 题目链接:3403. 从盒子中找出字典序最大的字符串 I 代码如下: class Solution { public:string answerString(string word, int numFriends) {if (numFriends 1) {return word;}string res;for (int i 0;i &…...
如何理解 IP 数据报中的 TTL?
目录 前言理解 前言 面试灵魂一问:说说对 IP 数据报中 TTL 的理解?我们都知道,IP 数据报由首部和数据两部分组成,首部又分为两部分:固定部分和可变部分,共占 20 字节,而即将讨论的 TTL 就位于首…...
【Redis】笔记|第8节|大厂高并发缓存架构实战与优化
缓存架构 代码结构 代码详情 功能点: 多级缓存,先查本地缓存,再查Redis,最后才查数据库热点数据重建逻辑使用分布式锁,二次查询更新缓存采用读写锁提升性能采用Redis的发布订阅机制通知所有实例更新本地缓存适用读多…...
JS手写代码篇----使用Promise封装AJAX请求
15、使用Promise封装AJAX请求 promise就有reject和resolve了,就不必写成功和失败的回调函数了 const BASEURL ./手写ajax/test.jsonfunction promiseAjax() {return new Promise((resolve, reject) > {const xhr new XMLHttpRequest();xhr.open("get&quo…...
Web后端基础(基础知识)
BS架构:Browser/Server,浏览器/服务器架构模式。客户端只需要浏览器,应用程序的逻辑和数据都存储在服务端。 优点:维护方便缺点:体验一般 CS架构:Client/Server,客户端/服务器架构模式。需要单独…...
在树莓派上添加音频输入设备的几种方法
在树莓派上添加音频输入设备可以通过以下步骤完成,具体方法取决于设备类型(如USB麦克风、3.5mm接口麦克风或HDMI音频输入)。以下是详细指南: 1. 连接音频输入设备 USB麦克风/声卡:直接插入树莓派的USB接口。3.5mm麦克…...
