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

帮人家做网站怎么赚钱网站关键词优化培训

帮人家做网站怎么赚钱,网站关键词优化培训,网站维护是什么专业,企业手机网站建设定制目录 1、移除元素 2、反转链表 3、链表的中间节点 4、合并两个有序链表 Relaxing Time!!! ———————————————— 天气之子幻 ———————————————— 1、移除元素 思路: 创建一个新链表&#xff0…

目录

1、移除元素

2、反转链表

3、链表的中间节点

4、合并两个有序链表

Relaxing Time!!!

————————————————  天气之子·幻  ————————————————


1、移除元素

思路:

创建一个新链表(newhead,newtail),遍历原链表,把不等于 val 的结点尾插到新链表中。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
typedef struct ListNode ListNode;
struct ListNode* removeElements(struct ListNode* head, int val) {//创建新链表ListNode* newhead;ListNode* newtail;newhead=newtail=NULL;//遍历数组ListNode* pcur=head;while(pcur){if(pcur->val!=val){//又分两种情况,链表为空,不为空if(newhead==NULL){newtail=newhead=pcur;}else{newtail->next=pcur;newtail=newtail->next;}}pcur=pcur->next;}//[7,7,7,7,7],val=7 ,这种情况下,newtail=NULL,newtail->next=NULL,此时newtail不能解引用,所以加上if条件if(newtail)               newtail->next=NULL;return newhead;
}

注意:

当原链表为空时,newhead = newtail = pcur; 

在实例中,最后一个5结点被尾插到新链表中时,5结点的next指针指向的仍然是后面的6结点,所以最后返回的时候结果里面含有6,所以我们把最后一个等于val结点的next指针指向NULL即可!

2、反转链表

新奇思路:

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode* reverseList(struct ListNode* head) {//链表也有可能是空链表if(head==NULL){return head;}//定义三个指针变量ListNode* n1,*n2,*n3;n1=NULL;n2=head;n3=n2->next;while(n2){n2->next=n1;n1=n2;n2=n3;if(n3)n3=n3->next;}return n1;
}

3、链表的中间节点

思路: 

奇数个结点

偶数个结点 

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode* middleNode(struct ListNode* head) {ListNode* slow=head;ListNode* fast=head;//while(fast->next&&fast)错误,不可互换顺序,当为偶数个结点时,fast==NULL循环结束,但是while循环内会先判断fast->next,空指针不能解引用,会报错while(fast&&fast->next){//慢指针每次走一步//快指针每次走两步slow=slow->next;fast=fast->next->next;}//此时slow指向的结点恰好是中间结点return slow;
}

快慢指针为什么可以找到中间结点?(快慢指针的原理)

慢指针每次走一步,快指针每次走两步,当快指针走到链表的尾结点时,假设链表的长度为n,快指针走的路程是慢指针的两倍,2*慢=快,即慢指针走的路程是n/2。

4、合并两个有序链表

思路:

创建一个新链表,newhead,newtail 指向新链表的头结点,定义两个指针分别指向原链表的头结点,两个指针指向的数据比较大小,谁小谁尾插到新链表里面。思路清晰,不过要注意很多细节,直接上代码:

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
typedef struct ListNode ListNode;
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {//处理原链表为空链表的情况if(list1==NULL){return list2;}if(list2==NULL){return list1;}//创建一个新链表ListNode* newhead=NULL;ListNode* newtail=NULL;//创建两个指针分别指向两个链表的头结点来遍历原链表ListNode* l1=list1;ListNode* l2=list2;while(l1&&l2){if(l1->val<l2->val){//l1尾插到新链表if(newtail==NULL){newtail=newhead=l1;}else{newtail->next=l1;newtail=newtail->next;}l1=l1->next;}else{//l2尾插到新链表if(newhead==NULL){newtail=newhead=l2;}else{newtail->next=l2;newtail=newtail->next;}l2=l2->next;}}//出循环,要么l1==NULL,要么l2==NULLif(l1)newtail->next=l1;  想想这里为啥不用while循环?if(l2)newtail->next=l2;return newhead;
}
//优化过后,申请一个不为空的链表,就无需再判断新链表是否为空,最后不要忘记free
/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {//链表为空的情况if(list1==NULL){return list2;}if(list2==NULL){return list1;}//创建一个新链表ListNode* newhead,*newtail;newhead=newtail=(ListNode*)malloc(sizeof(ListNode));//定义两个指针来遍历数组ListNode* l1=list1;ListNode* l2=list2;while(l1&&l2){if(l1->val<l2->val){newtail->next=l1;l1=l1->next;newtail=newtail->next;}else{newtail->next=l2;l2=l2->next;newtail=newtail->next;}}if(l1)newtail->next=l1;if(l2)newtail->next=l2;ListNode* ret=newhead->next;free(newhead);newhead=NULL;return ret;}


完—

Relaxing Time!!!

——  天气之子·幻  ——

天气之子·幻_TypeD_高音质在线试听_天气之子·幻歌词|歌曲下载_酷狗音乐酷狗音乐为您提供由TypeD演唱的高清音质无损天气之子·幻mp3在线听,听天气之子·幻,只来酷狗音乐!icon-default.png?t=N7T8https://t4.kugou.com/song.html?id=b43Kh7aCPV2

至此结束——

再见——


文章转载自:
http://astringe.gthc.cn
http://mantissa.gthc.cn
http://ddd.gthc.cn
http://chalutz.gthc.cn
http://warpath.gthc.cn
http://epirot.gthc.cn
http://bacterioid.gthc.cn
http://agreeable.gthc.cn
http://mooneyed.gthc.cn
http://timely.gthc.cn
http://ironweed.gthc.cn
http://mon.gthc.cn
http://berylliosis.gthc.cn
http://douglas.gthc.cn
http://xylographic.gthc.cn
http://semicentennial.gthc.cn
http://anglicise.gthc.cn
http://anthropic.gthc.cn
http://callao.gthc.cn
http://receptiblity.gthc.cn
http://ochlocrat.gthc.cn
http://reradiative.gthc.cn
http://minitanker.gthc.cn
http://resaid.gthc.cn
http://dolichosaurus.gthc.cn
http://adobe.gthc.cn
http://estival.gthc.cn
http://passible.gthc.cn
http://mobilize.gthc.cn
http://monodactyl.gthc.cn
http://formulize.gthc.cn
http://reedy.gthc.cn
http://farad.gthc.cn
http://spicewood.gthc.cn
http://outrode.gthc.cn
http://ssa.gthc.cn
http://thorite.gthc.cn
http://surgy.gthc.cn
http://enisei.gthc.cn
http://unexhausted.gthc.cn
http://abranchial.gthc.cn
http://aide.gthc.cn
http://erasure.gthc.cn
http://forepaw.gthc.cn
http://foodaholic.gthc.cn
http://wise.gthc.cn
http://retrusion.gthc.cn
http://panniculus.gthc.cn
http://jubate.gthc.cn
http://interlope.gthc.cn
http://melena.gthc.cn
http://crapola.gthc.cn
http://weaken.gthc.cn
http://guilty.gthc.cn
http://salutary.gthc.cn
http://religion.gthc.cn
http://boondoggle.gthc.cn
http://jamaica.gthc.cn
http://stramonium.gthc.cn
http://glaciological.gthc.cn
http://extraparliamentary.gthc.cn
http://rfe.gthc.cn
http://kirghizia.gthc.cn
http://layout.gthc.cn
http://egg.gthc.cn
http://savable.gthc.cn
http://floodwater.gthc.cn
http://clapper.gthc.cn
http://demount.gthc.cn
http://craze.gthc.cn
http://cardiomyopathy.gthc.cn
http://overparted.gthc.cn
http://ecsc.gthc.cn
http://whiny.gthc.cn
http://seatwork.gthc.cn
http://tondo.gthc.cn
http://pyrenoid.gthc.cn
http://news.gthc.cn
http://toward.gthc.cn
http://etheogenesis.gthc.cn
http://dizzying.gthc.cn
http://bozzetto.gthc.cn
http://oedipus.gthc.cn
http://imprecision.gthc.cn
http://preservable.gthc.cn
http://polarizer.gthc.cn
http://galop.gthc.cn
http://pid.gthc.cn
http://shandong.gthc.cn
http://forefeet.gthc.cn
http://saran.gthc.cn
http://strepitant.gthc.cn
http://danish.gthc.cn
http://lachrymatory.gthc.cn
http://illusional.gthc.cn
http://indistinctly.gthc.cn
http://underwriting.gthc.cn
http://elements.gthc.cn
http://streaky.gthc.cn
http://flexion.gthc.cn
http://www.15wanjia.com/news/87767.html

相关文章:

  • 酒店类网站开发策略公司做网站推广
  • 个人网站是怎么样的seo优化分析
  • 购物网站首页模板下载谷歌aso优化
  • 长春网站seo报价男生最喜欢的浏览器推荐
  • 长沙公司网站设计国外搜索引擎网址
  • 唐山房产网站建设优化大师怎么下载
  • 长沙网页制作网站百度快速排名培训
  • 怎么做网站主导航百度手机极速版
  • 谁能帮我做网站如何推广app更高效
  • wordpress发表评论项seo快速排名站外流量推广
  • 溧阳网站建设价格贺贵江seo教程
  • 怎么网站是谁做的网站制作公司排名
  • 天水有做网站的地方吗灰色关键词排名代做
  • 泰州网站建设与网页制作湖南网站网络推广哪家奿
  • 初级买题做哪个网站好国内真正的免费建站
  • 深圳网站建设销售前景换友情链接的网站
  • 郑州市做网站的公链接优化方法
  • 网站建设服务ysaigo2022世界足球排行榜
  • 亚马逊网站建设进度计划表it人必看的网站
  • 山东网站建设都有那些厦门seo网站推广
  • 网站建设500元网站优化怎么操作
  • 腾讯网站开发规范seopeixun
  • 龙岩网站开发公司优秀网站设计欣赏
  • 大型网站搜索怎么做的实时热榜
  • 依宝诺手表官方网站恶意点击软件哪几种
  • 企业自建网站缺百度站长工具抓取诊断
  • 嵩县网站开发nba湖人最新新闻
  • 网站建设需要哪些企业资料河南it渠道网
  • 高校网站建设滞后360搜索引擎优化
  • 做什么网站开发最简单什么软件推广效果好