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

jsp网站开发实例教学郑州电商网站建设

jsp网站开发实例教学,郑州电商网站建设,企业推广系统,mt7620a做网站-之前我们学过储存数据的一种表——顺序表,那么为什么还有链表呢 首先我们回顾一下顺序表 顺序表是物理地址连续的一段内存空间(数组),我们通过动态内存开辟的, 那么: 顺序表也有自己的一些优点&#xff0c…

-之前我们学过储存数据的一种表——顺序表,那么为什么还有链表呢
首先我们回顾一下顺序表
顺序表是物理地址连续的一段内存空间(数组),我们通过动态内存开辟的,
那么:在这里插入图片描述
顺序表也有自己的一些优点,比如我们之前做过的一些题,可以通过下标来快速完成,因为他的地址是连续的所以只要利用下标的加减就可以实现

既然顺序表有缺点,那么我们就有了链表。(按需求申请空间)

在这里插入图片描述
在这里插入图片描述
通过插入数据,来理解链表
在这里插入图片描述
在这里插入图片描述

打印函数
在这里插入图片描述

在链表的尾部插入数据

在这里插入图片描述

代码:


SLTPushBack(SLTNode* plist, SLTDataType x)
{//首先要开辟一个结构体来把要插入的数据的内容写进去,在之前的BuySListNode函数就是干这个事情的SLTNode* newnode = BuySListNode(x);SLTNode* tail = plist;while (tail->next != NULL){tail = tail->next;}tail->next = newnode;
}

上述的尾插是建立在之前已经头插了几个节点的情况下的
在这里插入图片描述

那么当链表还是空的时候,这样的尾插还适用吗
在这里插入图片描述
知道了这个问题我们来修改代码:
在这里插入图片描述
那么想要修改plist就要传址,
在这里插入图片描述
尾插总结图
在这里插入图片描述
头插:头插不管什么情况都要挪动plist的,所以也是传址操作,上面已经写到过头插的指针变换了,这里我们直接写代码就行

void TestSList3(){SLTNode* plist = NULL;SLTPushFront(&plist,5);SLTPushFront(&plist, 4);SLTPushFront(&plist, 3);SLTPushFront(&plist, 2);SLTPrin(plist);}void SLTPushFront(SLTNode** head, SLTDataType x)
{SLTNode* newnode = BuySListNode(x);newnode->next = *head;*head = newnode;}

在这里插入图片描述

尾删
在这里插入图片描述
代码:

//尾删SLTPopBack(&plist);SLTPrin(plist);SLTPopBack(&plist);SLTPrin(plist);SLTPopBack(&plist);SLTPrin(plist);SLTPopBack(&plist);SLTPrin(plist);SLTPopBack(&plist);SLTPrin(plist);
void SLTPopBack(SLTNode** head)
{assert(*head);if ((*head)->next == NULL){free(*head);*head = NULL;}else{SLTNode* stail = NULL;SLTNode* tail = *head;while (tail->next!=NULL){stail = tail;tail = tail->next;}free(tail);stail->next = NULL;}
}

在这里插入图片描述

头删
在这里插入图片描述

代码:

SLTPopFront(&plist);SLTPrin(plist);SLTPopFront(&plist);SLTPrin(plist);SLTPopFront(&plist);SLTPrin(plist);SLTPopFront(&plist);SLTPrin(plist);void SLTPopFront(SLTNode** head)
{assert(*head);SLTNode* newnode = (*head)->next;free(*head);*head = newnode;
}

在这里插入图片描述

查找链表中的数的指针,并改变这个指针所指节点的数据

在这里插入图片描述
代码:

//查找链表中的一个值的指针,并且改变他SLTNode* newnode = SLTFind(plist, 3);newnode->data = 20;SLTPrin(plist);
SLTNode* SLTFind(SLTNode* head, SLTDataType x)
{SLTNode* cur = head;while (cur != NULL){if (cur->data == x){return cur;}cur = cur->next;}return NULL;
}

在Pos位置插入节点
在这里插入图片描述
代码:

//在指定数据的指针pos位置前插入一个节点SLTNode* pos = SLTFind(plist, 3);//先查找到3所对应的指针posSLTnsert(&plist, pos, 30);SLTPrin(plist);
void SLTnsert(SLTNode** head, SLTNode* pos, SLTDataType x)
{assert(pos);if (pos == *head){SLTPushFront(head, x);//头插}else{SLTNode* prev = *head;while (prev->next != pos){prev = prev->next;//找到pos位置之前的那个节点的指针}SLTNode* newnode= BuySListNode(x);//为要插入的数据创建一个节点prev->next = newnode;newnode->next = pos;}
}

在这里插入图片描述
在pos位置之后插入节点
在这里插入图片描述
代码:

SLTNode* pos = SLTFind(plist, 3);//先查找到3所对应的指针pos/*	SLTnsert(&plist, pos, 30);SLTPrin(plist);*/SLTnsertAfter(plist, pos, 30);SLTPrin(plist);
void SLTnsertAfter(SLTNode* head, SLTNode* pos, SLTDataType x)
{assert(head);SLTNode* newnode = BuySListNode(x);//为要插入的数据创建一个节点newnode->next = pos->next;pos->next = newnode;
}

删除Pos位置的节点
在这里插入图片描述

SLTErase(&plist, pos);pos = NULL;SLTPrin(plist);void SLTErase(SLTNode** head, SLTNode* pos)
{assert(pos);if (pos == *head){SLTPopFront(head);//头删}else{SLTNode* per = *head;while (per->next!=pos){per = per->next;}per->next = pos->next;free(pos);}
}

删除pos位置之后的节点
在这里插入图片描述
代码:

SLTNode* pos = SLTFind(plist, 3);//先查找到3所对应的指针posSLTEraseAfter(pos);SLTPrin(plist);
void SLTEraseAfter(SLTNode* pos)
{assert(pos->next);assert(pos);SLTNode* per = pos->next;pos->next = per->next;free(per);}

在这里插入图片描述释放链表
在这里插入图片描述

http://www.yayakq.cn/news/109591/

相关文章:

  • 自动提卡的网站怎么做的html5怎么做二手网站
  • 烟台小学网站建设西安seo搜推宝
  • 单页网站如何做网站建设公司汉狮网络
  • 电商网站建设最好的公司重庆大学建设管理与房地产学院网站
  • 做货代还有什么网站可以加人网上找客户用什么软件
  • 做外汇哪个网站看外国消息老哥们给个关键词
  • 贵州省建设厅网站多少韩国免费行情网站的推荐理由
  • 会员网站免费建设国外美容网站
  • 网站备案地址简单个人网站开发
  • 济南专业网站托管公司做宴会有哪些素材网站
  • 苏州企业网站关键词优化石狮市建设局网站
  • 温州网站建设首选龙诚互联代理网页游戏代理
  • 连接器零售在什么网站做网站建设点击打开指定网页
  • 乐清网站设计公司哪家好北京朝阳区二手房出售信息
  • 外贸网站和内贸住房与城乡建设部网站职责
  • 十款免费软件app下载入口百度推广seo
  • 成都著名网站网站建设管理考核办法
  • 建设淘宝客网站源码怎么弄网站建设是属于什么岗位
  • 东莞网站制作公司报价进服务器编辑网站怎么做
  • 粉红色的网站首页有没有网站可以做试卷
  • 网站和微信同步建设抖音代运营报价单
  • 专业的营销型网站建设wordpress缓存首页不正常
  • 响应式购物网站模板wordpress 用户发帖
  • 设计最简单的企业网站高校思政教育工作网站建设
  • 蓬莱网站建设价格研究网站建设
  • 网站制作设计教程dede网站后台地址扫描
  • 泉州网站建设网站制作南宁seo推广服务
  • 网站建设与开发 教材网站建设2019
  • 怎么样在服务器上建设网站wordpress获取分类下所有文章
  • 怎样看网站是谁做的衣服定制app