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

网站显示建设中页面嘉兴百度快照优化排名

网站显示建设中页面,嘉兴百度快照优化排名,推动,私人定制网站建设一.实现一个单链表&#xff08;无头单向不循环&#xff09; 我们首先实现一个无头单向不循环单链表。 写出基本的增删查改功能&#xff0c;以及其它的一些功能&#xff08;可忽略&#xff09;。 #include<stdio.h> #include<assert.h> #include<stdlib.h>…

一.实现一个单链表(无头单向不循环)

我们首先实现一个无头单向不循环单链表。

写出基本的增删查改功能,以及其它的一些功能(可忽略)。

#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
typedef int SLTDataType;typedef struct SListNode
{SLTDataType data;struct SListNode* next;
}SLTNode;SLTNode* BuyListNode(SLTDataType x)
{SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));if (newnode == NULL){printf("malloc failed.\n");exit(-1);}newnode->data = x;newnode->next = NULL;
}void SListPrint(SLTNode* phead)
{SLTNode* cur = phead;while (cur != NULL){printf("%d->", cur->data);cur = cur->next;}printf("NULL\n");
}void SListPushBack(SLTNode** pphead, SLTDataType x)
{SLTNode* newnode = BuyListNode(x);if (*pphead == NULL){*pphead = newnode;}else{//找到尾结点SLTNode* tail = *pphead;while (tail->next != NULL){tail = tail->next;}tail->next = newnode;}
}void SListPushFront(SLTNode** pphead, SLTDataType x)
{SLTNode* newnode = BuyListNode(x);newnode->next = *pphead;*pphead = newnode;
}void SListPopBack(SLTNode** pphead)
{assert(*pphead != NULL);if ((*pphead)->next == NULL){free(*pphead);*pphead = NULL;}else{SLTNode* tail = *pphead;SLTNode* prev = NULL;while (tail->next != NULL){prev = tail;tail = tail->next;}free(tail);tail = NULL;prev->next = NULL;}
}void SListPopFront(SLTNode** pphead)
{assert(*pphead);SLTNode* next = (*pphead)->next;free(*pphead);*pphead = next;
}SLTNode* SListFind(SLTNode* phead, SLTDataType x)
{SLTNode* cur = phead;while (cur){if (cur->data == x){return cur;}else{cur = cur->next;}}return NULL;
}void SListInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x)
{SLTNode* newnode = BuyListNode(x);if (*pphead == pos){newnode->next = *pphead;*pphead = newnode;}else{SLTNode* posPrev = *pphead;while (posPrev->next != pos){posPrev = posPrev->next;}posPrev->next = newnode;newnode->next = pos;}
}void SListErase(SLTNode** pphead, SLTNode* pos)
{if (*pphead == pos){*pphead = pos->next;free(pos);}else{SLTNode* prev = *pphead;while (prev->next != pos){prev = prev->next;}prev->next = pos->next;free(pos);}
}void SListDestroy(SLTNode** pphead)
{assert(*pphead);SLTNode* cur = *pphead;SLTNode* next = (*pphead)->next;while (next){free(cur);cur = next;next = next->next;}free(cur);*pphead = NULL;
}//通过一趟遍历确定长度为n的单链表中值最大的结点
SLTNode* SListFindMax(SLTNode* pphead)
{assert(pphead);SLTNode* cur = pphead;SLTNode* maxnode = pphead;SLTDataType max = pphead->data;while (cur){if (cur->data > max){max = cur->data;maxnode = cur;}cur = cur->next;}return maxnode;
}

二.原地逆转

接下来我们要写一个接口,实现:将链表中所有结点的链接方向“原地”逆转,即要求仅利用原表的存储空间,换句话说,要求空间复杂度为O(1)

那么,我们需要将链表遍历,进行逆转,改变链接方向 时,要尤其注意,避免行差踏错。

//将链表中所有结点的链接方向“原地”逆转,即要求仅利用原表的存储空间,换句话说,要求空间复杂度为O(1)
void SListReverse(SLTNode** pphead) 
{SLTNode* head = *pphead;   //此指针在每次循环中始终指向当前链表的头SLTNode* tmp = head->next; //此指针在每次循环中始终指向要被后删头插的节点SLTNode* oldhead = *pphead;   //此指针在每次循环中始终指向原本的头结点,不会改变指向while (tmp) //如果tmp为空,则代表逆序结束,旧头的next已经是空的了,成为新链表的末尾{oldhead->next = tmp->next; //将tmp架空,实际是后删操作的一部分tmp->next = head; //让tmp变成新的头,实际是头插操作的一部分 head = tmp; //换头tmp = oldhead->next; //让tmp变成下次循环中待删除的节点}*pphead = head;
}

或许仅仅一段代码不足以让你理解,我们可以来看下面的图。

对照着代码,每一次循环就是下面的一行。

最后一行即为逆转后的链表。

 

 三.测试运行

最后,我们来看一下上面代码的运行效果。

我们可以写一个测试函数。

void TestSList()
{SLTNode* plist = NULL;SListPushBack(&plist, 1);SListPushBack(&plist, 2);SListPushBack(&plist, 3);SListPushBack(&plist, 4);SListPushBack(&plist, 5);SListPrint(plist);SListReverse(&plist);SListPrint(plist);SListDestroy(&plist);}int main()
{TestSList();return 0;
}

运行结果

这样,我们就实现了链表的原地逆转。 


文章转载自:
http://brazenfaced.xnLj.cn
http://psychologism.xnLj.cn
http://brownette.xnLj.cn
http://head.xnLj.cn
http://resay.xnLj.cn
http://wharfinger.xnLj.cn
http://abiogenist.xnLj.cn
http://brother.xnLj.cn
http://malodorant.xnLj.cn
http://archaism.xnLj.cn
http://granite.xnLj.cn
http://garnishment.xnLj.cn
http://extra.xnLj.cn
http://push.xnLj.cn
http://preestablish.xnLj.cn
http://sothiacal.xnLj.cn
http://baisakh.xnLj.cn
http://lipoma.xnLj.cn
http://lophophorate.xnLj.cn
http://nyctanthous.xnLj.cn
http://formfitting.xnLj.cn
http://erp.xnLj.cn
http://feazings.xnLj.cn
http://addicted.xnLj.cn
http://scorzonera.xnLj.cn
http://merca.xnLj.cn
http://allocator.xnLj.cn
http://inanimation.xnLj.cn
http://antifriction.xnLj.cn
http://nammet.xnLj.cn
http://expressway.xnLj.cn
http://taciturnity.xnLj.cn
http://jutty.xnLj.cn
http://usphs.xnLj.cn
http://forebear.xnLj.cn
http://teleutospore.xnLj.cn
http://delighted.xnLj.cn
http://impartibility.xnLj.cn
http://onside.xnLj.cn
http://monoideism.xnLj.cn
http://presto.xnLj.cn
http://superconscious.xnLj.cn
http://chuck.xnLj.cn
http://brushback.xnLj.cn
http://infuse.xnLj.cn
http://crockpot.xnLj.cn
http://autoincrement.xnLj.cn
http://guitarfish.xnLj.cn
http://actually.xnLj.cn
http://feldspathoid.xnLj.cn
http://proteoglycan.xnLj.cn
http://standpipe.xnLj.cn
http://toothless.xnLj.cn
http://exoergic.xnLj.cn
http://obelus.xnLj.cn
http://multicylinder.xnLj.cn
http://disafforestation.xnLj.cn
http://pyroelectricity.xnLj.cn
http://thu.xnLj.cn
http://teens.xnLj.cn
http://rabbitfish.xnLj.cn
http://photochromy.xnLj.cn
http://phlebography.xnLj.cn
http://skewer.xnLj.cn
http://weatherwise.xnLj.cn
http://kilohm.xnLj.cn
http://despoilment.xnLj.cn
http://vacuolating.xnLj.cn
http://precalcic.xnLj.cn
http://adenosis.xnLj.cn
http://windflower.xnLj.cn
http://huisache.xnLj.cn
http://remunerate.xnLj.cn
http://interknot.xnLj.cn
http://kindly.xnLj.cn
http://pride.xnLj.cn
http://groveling.xnLj.cn
http://rubral.xnLj.cn
http://descriptive.xnLj.cn
http://divagate.xnLj.cn
http://sudbury.xnLj.cn
http://preliberation.xnLj.cn
http://intermediate.xnLj.cn
http://disencumber.xnLj.cn
http://wedeln.xnLj.cn
http://benthic.xnLj.cn
http://uproot.xnLj.cn
http://crossbill.xnLj.cn
http://leadin.xnLj.cn
http://electrotonic.xnLj.cn
http://quincy.xnLj.cn
http://maths.xnLj.cn
http://chauvinistic.xnLj.cn
http://westerly.xnLj.cn
http://fawny.xnLj.cn
http://misimpression.xnLj.cn
http://possibilistic.xnLj.cn
http://paedomorphism.xnLj.cn
http://rhymer.xnLj.cn
http://aposematic.xnLj.cn
http://www.15wanjia.com/news/61290.html

相关文章:

  • 网站建设模块需求分析网站优化关键词排名公司
  • 做旅游网站推广专业网站推广优化
  • 做兼职发传单在哪个网站好招聘吉安seo网站快速排名
  • 天空人体网站怎么做企业seo培训
  • 南通做网站优化公司百度不收录网站怎么办
  • 做医美设计的网站宁德市安全教育平台
  • 游戏网站建设论文西安分类信息seo公司
  • 运输房产网站建设2022最新免费的推广引流软件
  • 多光营销软件网站百度竞价排名系统
  • 网站建设经验河北seo人员
  • 洛阳网站制作哪家好郑州seo询搜点网络效果佳
  • 自己做副业可以抢哪个网站长沙seo袁飞
  • 做3d动画网站列举网络推广的方式
  • 什邡网站建设百度一下电脑版首页
  • 廊坊网站seo服务百度营消 营销推广
  • 资源分享网站怎么做nba排名赛程
  • wordpress空两格衡水seo营销
  • 网站建设服务有免费做网站的吗
  • 官网建设报价seo综合查询工具下载
  • 家用机能否做网站服务器关键词排名优化教程
  • 怎么找网站建设域名搜索引擎
  • 武汉简单做网站百度竞价账户
  • php与python做网站网络热词2023
  • html的制作网站的优点网络口碑营销的成功案例
  • 网站友情链接如何做识图
  • 网站怎么做微博认证吗深圳百度seo优化
  • 公司网站制作怎么弄石家庄seo推广
  • 自助建站免费自助建站网站济南seo网站关键词排名
  • 品牌网站策划方案广告信息发布平台
  • 微信手机网站源码企业网络营销策略案例