带头结点和不带头结点的单链表的尾插法以及各种操作

不带头节点的单链表如何头插(多图易懂) 文章目录缘起带头节点的头插不带头节点的头插错误的代码为什么错误如何修改返回新的头指针二级指针 缘起 本文想说的是单向非循环链表的头插。单向非循环链表,可以是带头节点的,也可以是不带头节点的。 对于前者,代码比较简单,后文会说。对于后者,不带头节点的单向链表的头插,我发现即使有多年工作经验的老鸟,也可能写出错误的代码。 带头节点的头插 #include <stdio.h> #include <assert.h> #include <stdlib.h> typedef s 阅读详情
 

一.带头结点的单链表

先说一下create()建立的链表,采用cycle的方式。

/*************************************************************

带头结点的单链表13-1-1ex3.cpp

1.建立单链表

2.求链表长度

3.在第i个位置插入元素(种方法)

4.删除指定序号的节点

由于本程序是带头节点的,所以在删除函数Del()和插入函数InsertList()

中,head均没有被改变,所以,主函数中,用了Del和InsertList之后

均没有改变head,在PrintList中,还可以继续把head传入。如果是这样

的话,这两个函数完全可以定义成void类型,而不是Node *类型的

只要将Create()定义成Node *就行,再在main()中定义一个指针head

将head=Create();以后这个head都不会变了。好像带头节点链表的这些

常规操作均不改变Head节点。

**************************************************************/

#include<stdio.h>

#include<stdlib.h>

//#include<string.h>

//#include<conio.h>

 

typedef struct student

{

         int data;

         struct student *next;

         //struct student *pre;

}Node;

 

 

int GetLength(Node *head)

{

         int n=0;

         Node *p;

         p=head->next;

         while(p!=NULL)

         {

                  p=p->next;

                  n++;

         }

         return n;

}

 

Node *InsertList(Node *head, int x, int i) //插入元素方法1

{

         Node *p, *q, *s;

         int j=1;

         p=head;

         if(i<1 || i>GetLength(head)+1)

         {

                  exit(1);

         }

         s=(Node *)malloc(sizeof(Node));

         s->data=x;

         while(j<=i)

         {

                  q=p;

                  p=p->next;

     
王道数据结构第二章(二)-链表 链表链表,其实就是一个数据一个指针。单链表就是每个结点除了存放数据元素,还要存储指向下一个节点的指针。和顺序表刚好互补,一个需要大片连续空间,改变容量不方便,一个不可以随机存取,还要靠一定空间存放指针。typedef <数据类型> <别名>eg:则int x = 1;等价于cc x = 1;struct LNode{ //定义单链表结点int data;//每个节点存放一个数据元素//指针指向下一个节点额,结构体后面是要加分号的。 阅读详情

相关推荐

四种创建单链表的方法

学习了这么久的数据结构,终于把链表吃透啦,下面是我整理的四种创建单链表的的方法,以及一些非常容易犯的错误,让我们一起来看看吧~

AIGC 1万+

发那科机器人编程软件fanuc roboguide授权补丁_工业机器人离线编程与应用:ROBOGUIDE V8.3版本的工程文件创建...

欢迎关注我们ROBOGUIDE是发那科机器人公司提供的一个离线编程工具,可模拟现实中的机器人和周边设备的布局,通过虚拟TP示教来模拟机器人的运动轨迹,同时可以验证方案的可行性和准确的周期时间。ROBOGUIDE是一款核心应用软件,具体的还包括搬运、弧焊、喷涂等其他模块。以最新的8.3版本为例进行讲解,对于未注册的版本将有30天的免费使用期限。开始菜单击开始菜单中的HandingPRO启动程序,第一...

weixin_39791446的博客 2925

MPU6050 vs BMX055 vs ICM20602:如何为你的项目选择最佳陀螺仪(附实测数据对比)

本文深度对比了MPU6050、BMX055和ICM20602三款主流六轴IMU传感器的核心性能。通过实测数据,分析了它们在精度、噪声、温漂、接口速度及资源占用上的差异,并提供了从项目需求出发的选型指南,帮助开发者根据预算、精度要求和处理器性能选择最合适的陀螺仪与加速度计组合。

h0i1j2k3l的博客 971

DPABI实战:手把手教你处理小鼠静息态fMRI数据(从Voxel Size到SPM完整流程)

本文详细介绍了使用DPABI处理小鼠静息态fMRI数据的完整流程,从Voxel Size调整到SPM分析,涵盖预处理、质量控制和可视化等关键步骤。针对小鼠数据特有的低分辨率和信噪比问题,提供了实战建议和避坑指南,帮助研究人员高效完成数据分析。

weixin_42663213的博客 477

用74LS194和555定时器DIY流水灯:一个经典的数字电路课程设计复盘(附Multisim仿真文件)

本文详细介绍了使用74LS194移位寄存器和555定时器搭建八路彩灯控制器的完整过程,包括硬件选型、电路设计、调试技巧及常见问题解决方案。作为经典的数字电路课程设计,该项目涵盖了EDA工具应用、电路原理图设计和Multisim仿真等核心技能,适合电子工程学习者实践参考。

weixin_29185199的博客 427

永久关闭Windows更新的5种方法

很多家用电脑,如果系统自动更新的话,会变得越来越卡顿,且硬件型号兼容也并不完美。那么我们该如何彻底关闭Win11的自动更新呢?以下准备了5种方法,您可以根据自身实际情况选择合适的方法!

qq_43652793的博客 1万+

【k8s故障处理篇】calico-kube-controllers状态为“ImagePullBackOff”解决办法

【k8s故障处理篇】calico-kube-controllers状态为“ImagePullBackOff”解决办法

jks212454的博客 2308

GEE 案例:基于陆地卫星8号(大气层顶反射率数据)LANDSAT/LC08/C02/T1_TOA的生态遥感指数RSEI计算、可视化和下载

摘要:基于GEE的遥感生态指数(RSEI)计算方法 本文介绍了利用Google Earth Engine(GEE)平台计算遥感生态指数(RSEI)的全流程方法。主要内容包括:研究区域定义、Landsat8数据获取与去云预处理、关键生态指标计算(地表温度LST、植被指数NDVI、湿度指数WET和建筑指数NDBSI)、主成分分析(PCA)降维处理,以及结果可视化与数据导出。通过结合多源遥感指标并采用归一化处理,构建了综合反映区域生态环境质量的RSEI指数。该方法为生态环境监测提供了高效的技术方案,所有计算过程均

此星光明博客 450

【嵌入式DIY实例-ESP32篇】-智能花园助手

本文介绍了一个基于ESP32的智能花园监控系统。系统使用ESP-EYE摄像头开发板,集成了土壤湿度传感器、DHT22温湿度传感器和电磁阀等模块,实现植物生长环境监测与自动灌溉功能。硬件部分详细说明了各传感器的接线方式,软件部分展示了如何通过Firebase实现数据存储和远程监控。系统可实时采集土壤湿度、空气温湿度等数据,并通过摄像头监控植物状态,当检测到环境参数异常时,可自动控制水泵进行灌溉,为植物提供最佳生长环境。

视觉与物联智能 263

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

上一篇: 带头结点和不带头结点的尾插法建立双链表
下一篇: 2种方法求解约瑟夫环问题
eric802
博客等级 码龄17年 24粉丝 10原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值