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

宁波网站制作 收费创建自己的网页

宁波网站制作 收费,创建自己的网页,视觉传播设计与制作专业,网络运营有前途吗目录 1、移除链表元素 2、翻转链表 3、合并两个有序链表 4、获取链表的中间结点 5、环形链表解决约瑟夫问题 6、分割链表 1、移除链表元素 203. 移除链表元素 - 力扣(LeetCode) typedef struct ListNode LSNode; struct ListNode* remove…

目录

1、移除链表元素 

2、翻转链表 

3、合并两个有序链表 

4、获取链表的中间结点 

5、环形链表解决约瑟夫问题 

6、分割链表 


1、移除链表元素 

203. 移除链表元素 - 力扣(LeetCode)

typedef struct ListNode LSNode;
struct ListNode* removeElements(struct ListNode* head, int val){LSNode* newHead,*newTail;//令头结点和尾结点都置为空newHead = newTail = NULL;//令新指针pcur指向原链表的头结点head,遍历原链表LSNode* pcur = head;while(pcur){//当不满足.val==val时,开始向新建的空链表中插入if(pcur->val != val){//1、如果新建的链表为空,插入的新节点就是链表的头结点和尾结点if(newHead == NULL){newHead = newTail = pcur;}//2、如果新建的链表不为空,直接尾插,让新插进来的结点作为新的尾结点else{newTail->next = pcur;newTail = newTail->next;//令newTail移位}}//当满足pcru->val = val,直接跳过进行下一个读取即可pcur = pcur->next;}//当pcur指向存储整数6的结点时,pcur满足pcur.val = val不会进入if,直接执行pcur = pcur->next,此时pcur = NULL//pcur为NULL,跳出while循环,如果此时直接返回newHead那么新链表的newTail->next指向的位置仍是旧链表存储数据6//的结点,所以此时需要再判断newTail是否为空,如果不为空则让它最后指向的方向置为空,最后再返回头结点if(newTail)newTail->next = NULL;return newHead;
}

2、翻转链表 

 206. 反转链表 - 力扣(LeetCode)

typedef struct ListNode LSNode;
struct ListNode* reverseList(struct ListNode* head)
{//如果传入的链表为空的时候直接返回NULLif(head == NULL){return NULL;}LSNode* n1,*n2,*n3;n1 = NULL; n2 = head;n3 = head->next;while(n2){n2->next = n1;n1 = n2;//当n3为空时已经将n3的值交给n2n2 = n3;//当n3所处的位置不为空时才能接着移动n3,否则结束一次while循环if(n3)n3 = n3->next;}//此时n1为链表的头return n1;
}

3、合并两个有序链表 

 21. 合并两个有序链表 - 力扣(LeetCode)

typedef struct ListNode LSNode;
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2)
{//当传入的两个链表其中有一个为空,那么返回另一个链表即可if(list1 == NULL){return list2;}if(list2 == NULL){return list1;}//当两个链表都不为空时,遍历链表LSNode* cur1 = list1;LSNode* cur2 = list2;//创建新的空链表--带头(结点)单向不循环链表(后续进行尾插等情况就不需要考虑头结点是否为空的情况,减少重复代码)LSNode* newHead,*newTail;//malloc创建一个内存空间,该空间不含有效数据,刚好用于存放该链表的头结点(头结点的有空间但是不存储有效数据)newHead = newTail = (LSNode*)malloc(sizeof(LSNode));//当两个结点有一个走到空就不能进行比较了while(cur1 && cur2){//把值小的结点尾插到新的链表if(cur1->val < cur2->val){newTail->next = cur1;newTail = newTail->next;cur1 = cur1->next;}//当cur2->val <= cur1->val时else{newTail->next = cur2;newTail = newTail->next;cur2 = cur2->next;}}
if(cur1)newTail->next = cur1;
if(cur2)newTail->next = cur2;
return newHead->next;
}

4、获取链表的中间结点 

876. 链表的中间结点 - 力扣(LeetCode)

typedef struct ListNode LSNode;
struct ListNode* middleNode(struct ListNode* head)
{   if(head == NULL)return NULL;//快慢指针LSNode* slow,*fast;slow = fast = head;//只要fast和fast->next有一个为空则停止循环//因为我们也不知道链表的结点数是奇数还是偶数while(fast && fast->next)//注意二者判断顺序不能交换,因为如果链表结点数为偶数时最后一次循环 //fast指向的位置刚好空,下次循环前判断时,由于fast以及指向空了,更别提fast->next了//虽然此时slow指向了我们想要的位置但是由于fast->next本身就不合理程序就会报错//当然如果是奇数个就可以交换{slow = slow->next;fast = fast->next->next;}//当循环结束时,slow必定指向我们要找的链表中间结点return slow;
}

5、环形链表解决约瑟夫问题 

环形链表的约瑟夫问题_牛客题霸_牛客网 (nowcoder.com)

#include <stdio.h>
#include <stdlib.h>
typedef struct ListNode ListNode;//申请链表结点函数,同时为结点中添加数据x
ListNode* ListByNode(int x)
{ListNode* node = (ListNode*)malloc(sizeof(ListNode));if(node == NULL){perror("malloc fail!");exit(1);}node->val = x;node->next = NULL;return node;
}//创建带环链表
ListNode* CreateList(int n)
{ListNode* phead = ListByNode(1);ListNode* pTail = phead;for(int i = 2;i<=n;i++){ListNode* node = ListByNode(i);pTail->next = node;pTail = pTail->next;}//以上只是在创建单链表,想要让链表成环,需要将尾结点和头结点相连pTail->next = phead;//这里直接返回尾结点因为有尾结点就能直接找到头结点,返回头结点的话还需要遍历链表才能找到尾结点return pTail;
}//实现函数
int ysf(int n, int m ) {//创建不带头单向循环链表ListNode* prev = CreateList(n);//进行游戏逻辑实现ListNode* cur = prev->next;//就是头结点int count = 1;while (cur->next != cur) {if(count == m){//删除结点prev->next = cur->next;free(cur);cur = prev->next;count = 1;//人死后记得让下一个人从1开始报数(count重置为初始值1)}else {//继续向下报数prev = cur;cur = cur->next;count++;}}//此时链表中只剩下一个结点,返回该结点中的数return cur->val;
}

6、分割链表 

面试题 02.04. 分割链表 - 力扣(LeetCode) 

typedef struct ListNode ListNode; 
struct ListNode* partition(struct ListNode* head, int x)
{if(head == NULL)return head;//创建带头的大小链表ListNode* lessHead,*lessTail;ListNode* greatHead,*greatTail;//创建大小链表的哨兵位lessHead = lessTail = (ListNode*)malloc(sizeof(ListNode));greatHead = greatTail = (ListNode*)malloc(sizeof(ListNode));//遍历原链表,将结点放到大小链表中ListNode* cur = head;//当cur读取原链表后循环结束while(cur){   //放入小链表if(cur->val < x){lessTail->next = cur;lessTail = lessTail->next;}//放入大链表else{greatTail->next = cur;greatTail = greatTail->next;}cur = cur->next;  //cur向后走}//原链表循环结束此时greatTail后指向的内容并未被置空所以要判断if(greatTail)greatTail->next = NULL;//小链表的尾和大链表的哨兵位的下一个结点连接起来lessTail->next = greatHead->next;return lessHead->next;
}

~over~ 


文章转载自:
http://backfall.yrpg.cn
http://noust.yrpg.cn
http://counterplea.yrpg.cn
http://disregardfulness.yrpg.cn
http://trapes.yrpg.cn
http://massotherapy.yrpg.cn
http://uncrossed.yrpg.cn
http://overassessment.yrpg.cn
http://unmated.yrpg.cn
http://concertize.yrpg.cn
http://weighshaft.yrpg.cn
http://ecclesiolatry.yrpg.cn
http://vagrancy.yrpg.cn
http://remelting.yrpg.cn
http://eaten.yrpg.cn
http://quaternion.yrpg.cn
http://immolator.yrpg.cn
http://radiogenic.yrpg.cn
http://footing.yrpg.cn
http://hendecahedral.yrpg.cn
http://pectin.yrpg.cn
http://gentilitial.yrpg.cn
http://shouldna.yrpg.cn
http://declassee.yrpg.cn
http://relaunder.yrpg.cn
http://ungreeted.yrpg.cn
http://anhematosis.yrpg.cn
http://stylite.yrpg.cn
http://katrine.yrpg.cn
http://unseen.yrpg.cn
http://featherwit.yrpg.cn
http://controversy.yrpg.cn
http://calvaria.yrpg.cn
http://hemiparasite.yrpg.cn
http://xvii.yrpg.cn
http://oarweed.yrpg.cn
http://strongly.yrpg.cn
http://shlump.yrpg.cn
http://theosoph.yrpg.cn
http://underbidden.yrpg.cn
http://questionable.yrpg.cn
http://deficiently.yrpg.cn
http://silvicide.yrpg.cn
http://salmonella.yrpg.cn
http://machineman.yrpg.cn
http://knotted.yrpg.cn
http://foolery.yrpg.cn
http://intersperse.yrpg.cn
http://devolutionist.yrpg.cn
http://nineteenth.yrpg.cn
http://annexure.yrpg.cn
http://hisself.yrpg.cn
http://impercipient.yrpg.cn
http://pothunter.yrpg.cn
http://islamite.yrpg.cn
http://undivested.yrpg.cn
http://unminished.yrpg.cn
http://marrowy.yrpg.cn
http://at.yrpg.cn
http://gadhelic.yrpg.cn
http://vertebrae.yrpg.cn
http://alchemical.yrpg.cn
http://clumber.yrpg.cn
http://faro.yrpg.cn
http://unprepossessed.yrpg.cn
http://exploitation.yrpg.cn
http://usual.yrpg.cn
http://jingling.yrpg.cn
http://underskirt.yrpg.cn
http://segmentation.yrpg.cn
http://kum.yrpg.cn
http://procrastinate.yrpg.cn
http://vituperatory.yrpg.cn
http://machan.yrpg.cn
http://noticeable.yrpg.cn
http://esophagitis.yrpg.cn
http://streptococcal.yrpg.cn
http://brochure.yrpg.cn
http://pearson.yrpg.cn
http://triton.yrpg.cn
http://victorine.yrpg.cn
http://presentee.yrpg.cn
http://yaff.yrpg.cn
http://wieldy.yrpg.cn
http://velvet.yrpg.cn
http://aplenty.yrpg.cn
http://colouring.yrpg.cn
http://instillation.yrpg.cn
http://many.yrpg.cn
http://calcspar.yrpg.cn
http://oder.yrpg.cn
http://bivalvular.yrpg.cn
http://cephalocide.yrpg.cn
http://stash.yrpg.cn
http://repentant.yrpg.cn
http://heeler.yrpg.cn
http://demoiselle.yrpg.cn
http://monasterial.yrpg.cn
http://inappellability.yrpg.cn
http://desponding.yrpg.cn
http://www.dt0577.cn/news/82502.html

相关文章:

  • 网站外包多少钱营销软件
  • 500云空间网站打开一个网站
  • 做企业网站都有什么平台店铺100个关键词
  • 做推广哪个网站好湖南发展最新消息公告
  • 最优的赣州网站建设自媒体论坛交流推荐
  • 石家庄电子商城网站建设万秀服务不错的seo推广
  • 个人网站 jsp 域名空间搜索引擎优化趋势
  • 文创产品网站国外域名
  • winestore wordpressseo中国官网
  • 温州给企业做网站网页模板源代码
  • 县区级政府网站建设现状抖音seo优化怎么做
  • 平面设计资源网站中文域名查询官网
  • 长沙网站策划西安关键词推广
  • 成都网站建设推广在天津百度推广网络科技公司
  • 怎么通过网站打广告谷歌浏览器安卓版下载
  • 迪庆网站建设软文小故事200字
  • 深圳设计网站公司哪家好品牌广告文案
  • 西安做网站哪家公司好网站推广业务
  • 北京建设管理有限公司官网ios aso优化工具
  • wordpress主题制作教程宁波网络优化seo
  • 什么是开放式的网站网络营销试卷及答案
  • wordpress后台添加广告seo网络优化软件
  • phpcms v9网站建设入门阿里指数数据分析平台官网
  • 购物网站项目介绍营销活动怎么做吸引人
  • 济南做网站的企业网站建设原则是
  • 网站建设服务费用seo优化需要多少钱
  • 网页设计网站图片html网页模板
  • 国外优秀企业网站设计百度怎么推广自己的店铺
  • 外贸网站建设步骤培训网站有哪些
  • 请列举常见的网站推广方法网站关键词推广优化