当前位置: 首页 > news >正文

长宁建设机械网站今天实时热搜榜排名

长宁建设机械网站,今天实时热搜榜排名,安全联盟这种网站建设,手机怎么建设网站单链表一.概念二.一些类型的创建三.尾插四.头插五.头删尾删六.打印链表七.单链表查找,任意位置插入,任意位置删除八.源代码一.概念 该篇链表博客是按照工程项目的格式来记录的,与平常的算法链表有些许不同,注意区分。 二.一些类型的创建 三.尾…

单链表

  • 一.概念
    • 二.一些类型的创建
    • 三.尾插
    • 四.头插
  • 五.头删尾删
  • 六.打印链表
  • 七.单链表查找,任意位置插入,任意位置删除
  • 八.源代码

一.概念

该篇链表博客是按照工程项目的格式来记录的,与平常的算法链表有些许不同,注意区分。

在这里插入图片描述

在这里插入图片描述

二.一些类型的创建

在这里插入图片描述

在这里插入图片描述

三.尾插

因为需要凭空插入一个数,所以我们肯定需要新开辟一个节点(newnode)来存放需要插入的数。之后我们需要找到原链表的尾部再将其插入就可以了。

这里尤其需要注意的一个点是:我们增加操作如果链表为空时需要改变头节点(phead),因为phead是一级指针,所以我们传参需要二级指针。

Test.c

在这里插入图片描述

SList.h
在这里插入图片描述

SList.c

在这里插入图片描述

四.头插

因为头插必定会改变头节点所以同样需要使用二级指针。同时让插入的节点变为头节点。

Test.c

在这里插入图片描述

SLIst.h

在这里插入图片描述

SList.c

在这里插入图片描述

五.头删尾删

SList.h

在这里插入图片描述

SList.c

尾删
在这里插入图片描述

头删

在这里插入图片描述

六.打印链表

SList.h

在这里插入图片描述

SList.c

在这里插入图片描述

七.单链表查找,任意位置插入,任意位置删除

SList.h

在这里插入图片描述

SLiist.c

查找

在这里插入图片描述

在pos位置前面插入

在这里插入图片描述

将pos位置删除

在这里插入图片描述

八.源代码

test.c

#include"SList.h"void TestList()
{SListNode* phead = NULL;//测试部分}int main()
{TestList();return 0;
}

SList.h

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>#define SLTDataType inttypedef struct {SLTDataType data;//这里将int类型替换成链表类型以符合工程书写习惯struct SListNode* next;
}SListNode;void SLPushBack(SListNode** phead,SLTDataType x);//尾插void SLPushFront(SListNode** phead, SLTDataType x);//头插void SLPopBack(SListNode** phead);//尾删void SLPopFront(SListNode** phead);//头删void SLPrint(SListNode* phead);//打印//查找
SListNode* SListFind(SListNode* phead, SLTDataType x);
void SListInsert(SListNode**pphead,SListNode* pos, SLTDataType x);//在pos位置前位置插入(注意pos是节点的指针)
void SListErase(SListNode**pphead,SListNode* pos);//删除pos位置

SList.c

#include"SList.h"void SLPushBack(SListNode** pphead, SLTDataType x)//尾插
{SListNode* newnode = (SListNode*)malloc(sizeof(SListNode));//开辟新节点来存放插入的数if (newnode == NULL)//如果开辟失败则返回错误{perror("malloc fail");return;}newnode->data = x;newnode->next = NULL;//初始化新节点if (*pphead == NULL)//注意*pphead就是phead{*pphead = newnode;}//如果链表里没有数直接插入数else{SListNode* tail = *pphead;while (tail->next != NULL){tail = tail->next;}//找到原链表尾部tail->next = newnode;//插入新节点}}void SLPushFront(SListNode** pphead, SLTDataType x)//头插
{SListNode* newnode = (SListNode*)malloc(sizeof(SListNode));//开辟一个新节点if (newnode == NULL)//判断是否开辟成功{perror("malloc fail");}newnode->data = x;newnode->next = *pphead;//让新的节点指向原本的头节点*pphead = newnode;//让新节点成为头节点
}void SLPopBack(SListNode** pphead)//尾删
{assert(*pphead!=NULL);//断言链表不能为空//找尾if ((*pphead)->next == NULL)//如果链表只有一个数{free(*pphead);//直接释放头节点*pphead = NULL;}else{SListNode* tail = *pphead;SListNode* prev = NULL;while (tail->next != NULL){prev = tail;tail = tail->next;}free(tail);//直接删掉tail节点tail = NULL;prev->next = NULL;}}void SLPopFront(SListNode** pphead)//头删
{assert(*pphead != NULL);//链表不能为空SListNode* first = *pphead;*pphead = first->next;//直接让头节点变为第二个数free(first);first = NULL;
}void SLPrint(SListNode* phead)//打印
{SListNode* start = phead;while (start != NULL){printf("%d ", start->data);start = start->next;}printf("NULL");
}SListNode* SListFind(SListNode* phead, SLTDataType x)//查找
{SListNode* cur = phead;while (cur->data != x&&cur!=NULL){cur = cur->next;}return cur;
}void SListInsert(SListNode**pphead,SListNode* pos, SLTDataType x)//任意位置插入
{if (pos == *pphead){SLPushFront(pphead,x);//头插}else{SListNode* pre = *pphead;while (pre->next != pos)//找到pos前面的位置{pre = pre->next;}SListNode* newnode = (SListNode*)malloc(sizeof(SListNode));//开辟新节点newnode->data = x;newnode->next = pos;//初始化新节点pre->next = newnode;//将pos前一个位置连接到新节点上}
}void SListErase(SListNode** pphead, SListNode* pos)//任意位置删除
{if (pos == *pphead){SLPopFront(pphead);//头删 }else{SListNode* pre = *pphead;while (pre->next != pos)//找到pos前面的位置{pre = pre->next;}pre->next = pos->next;//删除free(pos);}
}
http://www.tj-hxxt.cn/news/49720.html

相关文章:

  • wordpress找不到页面内容编辑郑州seo优化外包顾问阿亮
  • 企业招聘网站模板站长工具seo综合查询怎么用
  • 徐城乡建设局网站百度官方客服平台
  • 独立商城系统网站建设新闻发布的网站
  • 网站群建设公司seo排名培训公司
  • 电脑网站打不开是什么原因造成的最佳磁力搜索引擎
  • 一品威客网站是用什么平台做的微信群推广
  • 做百度网站每年的费用多少最好的网站推广软件
  • 网站支付界面怎么做常州百度seo排名
  • 上海信息科技有限公司软件网站开发免费自助建站平台
  • 商城网站开发网国产系统2345
  • 哈尔滨网站建设教程网站模板下载
  • 建材外贸网站建设加强服务保障满足群众急需ruu7
  • 郑州专业做网站企业凡科建站
  • 建设马克思主义学院网站网图识别在线百度
  • 推广型网站建设地址百度网站推广关键词怎么查
  • 微信网站建站平台市场调研报告怎么写的
  • 怎么给QQ名片做网站优化大师哪个好
  • wordpress+微信悬浮百度推广seo优化
  • 百度为何不收录你的网站产品页百度人工客服在线咨询
  • 一个一起做网站网站优化检测工具
  • 八年级信息做网站所用软件网站客服系统
  • 网站后缀net数字营销包括哪六种方式
  • qq刷网站空间武汉新闻最新消息
  • 做亚马逊有哪些站外折扣网站全国疫情最新报告
  • wordpress无法显示向导太原关键词排名优化
  • wordpress.html插件seo推广网络
  • 网站加入搜索引擎怎么做流量主广告点击自助平台
  • 武当王也高清壁纸北京网站优化指导
  • c 网站建设综合报告网络营销成功案例有哪些