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

宁波专业网站seo公司福州小程序开发公司列表

宁波专业网站seo公司,福州小程序开发公司列表,网站上线模板,seo引擎搜索网站关键词这里写目录标题 反转链表合并两个有序链表分割链表 反转链表 1、题目#xff1a; 2.思路  思路1#xff1a;建立一个newHead,取一个节点进行头插。具体做法如下#xff01; 建立一个newHead(新头)#xff0c;由于一个节点里面存的是下一个节点的地址#xff0c;如果取… 这里写目录标题 反转链表合并两个有序链表分割链表 反转链表 1、题目 2.思路  思路1建立一个newHead,取一个节点进行头插。具体做法如下 建立一个newHead(新头)由于一个节点里面存的是下一个节点的地址如果取一个节点下来进行头插那么要取的下一个节点的地址找不到因此定义n1,n2,n1用来往下拿结点进行头插n2预备下一次要的节点 代码如下 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/ struct ListNode* reverseList(struct ListNode* head) {if(head NULL){return NULL;}struct ListNode* newHead NULL;//n1为向下取得插入的节点struct ListNode* n1 head;//n2是给n1准备的节点struct ListNode* n2 head-next;while(n1){n1-next newHead;newHead n1;n1 n2;//当n2为NULL时n2没有取得节点了if(n2){n2 n2-next;}}return newHead; }思路2把指针翻转把指针反转的意思是把存节点的地址交换定义三个指针n1,n2,n3,n1 NULL,n2 head,n3 head-next,n2为第一个节点翻转n2-next n1,n2里面原来存的地址找不到因此要n3存下一个节点的地址这样这个题就可以反转了 struct ListNode* reverseList(struct ListNode* head) {if(head NULL){return NULL;}struct ListNode* n1 NULL;struct ListNode* n2 head;struct ListNode* n3 head-next;while(n2){n2-next n1;n1 n2;n2 n3;if(n3){n3 n3-next;}}return n1; }合并两个有序链表 1、题目 2、思路   这个题建立一个新链表取小的数尾插即可这儿有一些技巧可以建立一个头结点直接尾插这样就省去了考虑newHead为NULL的情况这个方法在一些题中有妙用 struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {if(l1NULL){return l2;}if(l2NULL){return l1;}//处理这个建立一个头节点把为NULL的一种可能性去掉struct ListNode* tmp (struct ListNode*)malloc(sizeof(struct ListNode));struct ListNode* tail tmp;while(l1l2){if(l1-vall2-val){tail-next l1;tail l1;l1 l1-next;}else{tail-next l2;tail l2;l2 l2-next;}}if(l1){tail-next l1;}if(l2){tail-next l2;}return tmp-next; }下面是一个正常的做法 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/ struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {if(l1 NULL){return l2;}if(l2 NULL){return l1;}struct ListNode* newHead,*tail;newHead NULL;while(l1l2){if(l1-vall2-val){if(newHead NULL){newHead tail l1;}else{tail-next l1;tail l1;}l1 l1-next;}else{if(newHead NULL){newHead tail l2;}else{tail-next l2;tail l2;}l2 l2-next;}}if(l1){tail-next l1;}if(l2){tail-next l2;}return newHead; }分割链表 1、题目 2、思路  建立两个链表一个是x的链表一个是x的链表最后把这两个链表组合起来返回头即可 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*///建立两个链表 //一个小于x //一个大于等于x struct ListNode* partition(struct ListNode* head, int x){/* ifhead NULL{return NULL;}*/struct ListNode* litterHead ( struct ListNode*)malloc(sizeof(struct ListNode));struct ListNode* litterTail litterHead;struct ListNode* biggerHead ( struct ListNode*)malloc(sizeof(struct ListNode));struct ListNode* biggerTail biggerHead;struct ListNode* cur head;while(cur){if(cur-valx){litterTail-next cur;litterTail cur;cur cur-next;}else{biggerTail-next cur;biggerTail cur;cur cur-next;}}biggerTail-next NULL;litterTail-next biggerHead-next;return litterHead-next; }完结
http://www.pierceye.com/news/136616/

相关文章:

  • 网站制作评价标准网站服务器怎么收费
  • 怎么建立自己的网站平台多少钱wordpress自建菜单
  • 深圳购物网站如何制作外贸网站 wordpress
  • 商品展示网站模板中国建设电工立网站
  • 网站推广的基本方法对于大部分网站来说都是适用的河北网站开发费用
  • 高安网站建设公司外链代发免费
  • 企业网站建设的价格wordpress免费用户
  • 怎么做门淘宝网站广播电台网站建设板块
  • ai效果图网站建设一个视频网站需要什么条件
  • 上海安全建设协会网站推广普通话的方法
  • 自己怎么做外贸英文网站网站建设外包
  • 南京专业网站开发团队wordpress如何构建页面
  • 济南网站优化排名推广python基础教程雪峰
  • 垂直购物网站建设代做网站推广的公司
  • 马云做一网站 只作一次网页界面设计使用色彩的作用是什么
  • 网站上传权限广西网站建设银行
  • 南通网站建设规划书wordpress 上传图片 500
  • 推广自身网站升级的网站显示什么
  • 网站与系统对接图文方案免费可信网站认证
  • 深圳设计网站速成班网站音频播放器代码
  • 域名注册最后是网站wordpress手机上传图片插件
  • 有哪些网站交互效果做的好的如何让google收录网站
  • wordpress到服务器配置云南seo
  • 常见网站安全漏洞行业网站如何推广
  • 网站开发实战项目苏州行业网站建设费用
  • 大团企业网站制作东莞网站制作的公司
  • 石家庄做网站公司的电话网站建设费用大概多少
  • 襄阳市网站建设怎么注册工作邮箱
  • 在百度里面做个网站怎么做的摄影大赛官网
  • 网站建设需要哪些的ps网站策划