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

如何做外贸营销型网站推广网站建设与优化

如何做外贸营销型网站推广,网站建设与优化,b2b网站如何做排名,网站建设 网络推广一、移除链表元素 移除链表中值为val的元素,并返回新的头节点 思路: 题目上这样说,我们就可以创建一个新的链表,将值不为val的节点,尾插到新的链表当中,最后返回新链表的头节点。 typedef struct ListNo…

一、移除链表元素

        移除链表中值为val的元素,并返回新的头节点

思路:

题目上这样说,我们就可以创建一个新的链表,将值不为val的节点,尾插到新的链表当中,最后返回新链表的头节点。

typedef struct ListNode ListNode;
struct ListNode* removeElements(struct ListNode* head, int val) {if(head==NULL){return NULL;}ListNode* newhead = (ListNode*)malloc(sizeof(ListNode));ListNode* ptail = head;ListNode* pcur = newhead;while (ptail) {if (ptail->val != val) {pcur->next = ptail;pcur = pcur->next;}ptail = ptail->next;}pcur->next=NULL;ListNode* ret = newhead->next;free(newhead);newhead = NULL;return ret;
}

        当然,这个题还有其他思路。

二、反转链表

        将链表反转,并返回反转后的链表的头节点

思路:

        创建三个指针变量,l1,l2,l3(指针初始指向如下图),遍历链表,先让l3=l2->next;再将l2的next指针指向l2;再l1指向l2,l2指向l3(l2下一个节点);直到遍历结束,结束条件为(l2等于NULL)此时l1指向的就是反转后的链表的头节点。

根据题目给的示例来分析

遍历数组,循环进行一次

l2不等于NULL循环继续

l2不等于NULL循环继续

l2不等于NULL循环继续

l2仍然不等于NULL,循环继续

到这里,l2已经遍历到了NULL,循环结束,此时l1指向的就是反转后链表的头节点,直接返回即可。

typedef struct ListNode ListNode;
struct ListNode* reverseList(struct ListNode* head) {ListNode* l1,*l2,*l3;l1=NULL;l2=head;while(l2){l3=l2->next;l2->next=l1;l1=l2;l2=l3;}return l1;
}

三、链表的中间节点

        看到这个题,本人一开始的想法是:遍历一遍链表,记录链表的节点个数,然后再遍历一次链表,寻找链表的中间节点;这样实现非常麻烦,现在使用一种新的方法来解决这个问题

思路:快慢指针

        定义两个快慢指针,fast和slow刚开始都指向链表的头节点,fast每次向前走两个节点,而slow指针每次向前走一个节点;最后当fast指针或者fast的next指针为NULL遍历结束;此时slow指向的就是链表的中间节点。

根据题所给的示例分析:
        链表个数为奇数

fast=fsat->next->next;

slow=slow->next;

           

遍历到这里,fast的next指针为空,循环结束;此时slow指向的就是链表的中间节点。

        链表的节点数为偶数

fast=fsat->next->next;

slow=slow->next;

循环到这里,fast为空,循环结束,此时slow指向的节点就是链表的中间节点。

typedef struct ListNode ListNode;
struct ListNode* middleNode(struct ListNode* head) {if(head==NULL){return NULL;}ListNode* fast=head;ListNode* slow=head;while(fast&&fast->next){fast=fast->next->next;slow=slow->next;}return slow;
}

四、合并两个有序链表

        合并两个有序链表,这里创建一个新的链表,将两个链表中较小小的数据依次尾插到新链表中,最后返回新链表的头节点即可。

        注意:这里需要注意,初始的两个链表可能为空,这里需要进判断,如果list1为空,就返回list1;如果list2为空,就返回list1。

根据题目示例分析

        比较l1和l2指向的节点的值大小,l1->val=l2->val(l1的不小于l2的),将l2指向节点尾插到新链表

        此时,l1->val < l2->val,将l1指向的节点尾插到新链表

        此时,l1->val < l2->val,将l1指向的节点尾插到新链表

比较l1和l2指向的节点的值大小,l2->val < l1->val,将l2指向节点尾插到新链表

        比较l1和l2指向的节点的值大小,l1->val=l2->val(l1的不小于l2的),将l2指向节点尾插到新链表

        l2为空,循环结束,这里l1的节点还没全部插到新链表中,这里直接 ptail->next=l1;即可。

注:这里使用动态内存来给newhead开辟空间,记得将其释放掉,养成好习惯。

typedef struct ListNode ListNode;
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {if(list1==NULL){return list2;}if(list2==NULL){return list1;}ListNode* l1=list1;ListNode* l2=list2;ListNode* newhead=(ListNode*)malloc(sizeof(ListNode));ListNode* ptail=newhead;while(l1 && l2){if(l1->val<l2->val){ptail->next=l1;l1=l1->next;}else{ptail->next=l2;l2=l2->next;} ptail=ptail->next;}if(l1){ptail->next=l1;}if(l2){ptail->next=l2;}ListNode* ret=newhead->next;free(newhead);newhead=NULL;return ret;
}

五、链表分割

将链表小于x的节点排在其余节点之前,不能改变原来顺序,最后返回排序好的链表的头指针。

思路:

        创建两个链表,一个链表l1,存放值小于val的节点;另一个链表l2,存放值大于等于val的节点。最后将两个链表连接起来,返回l1链表的头节点即可。

这里需要注意:再l2链表的结尾,要将尾节点的next指针置为NULL;

#include <cstddef>
class Partition {
public:ListNode* partition(ListNode* pHead, int x) {// write code hereListNode* list1,*l1;l1=list1=(ListNode*)malloc(sizeof(ListNode));ListNode* list2, *l2;l2=list2=(ListNode*)malloc(sizeof(ListNode));ListNode* ptail=pHead;while(ptail){if(ptail->val<x){//尾插到l1里l1->next=ptail;l1=l1->next;}else{l2->next=ptail;l2=l2->next;}ptail=ptail->next;}l2->next=NULL;l1->next=list2->next;ListNode* ret=list1->next;free(list1);free(list2);list1=list2=NULL;return ret;}
};


文章转载自:
http://dinncosalvershaped.bkqw.cn
http://dinncomappery.bkqw.cn
http://dinncobitnik.bkqw.cn
http://dinncoundescribed.bkqw.cn
http://dinncobrachydactylic.bkqw.cn
http://dinncoempaistic.bkqw.cn
http://dinncounobscured.bkqw.cn
http://dinncochirpy.bkqw.cn
http://dinncoorthographer.bkqw.cn
http://dinncomatronymic.bkqw.cn
http://dinncoistanbul.bkqw.cn
http://dinncoghillie.bkqw.cn
http://dinncodesoxycorticosterone.bkqw.cn
http://dinncolimn.bkqw.cn
http://dinncoschlemiel.bkqw.cn
http://dinncohappening.bkqw.cn
http://dinncochewink.bkqw.cn
http://dinncoantipyrotic.bkqw.cn
http://dinncoantipersonnel.bkqw.cn
http://dinncorosulate.bkqw.cn
http://dinncotawny.bkqw.cn
http://dinnconormanesque.bkqw.cn
http://dinncopinniped.bkqw.cn
http://dinncoreveller.bkqw.cn
http://dinncoconvictively.bkqw.cn
http://dinncothymicolymphatic.bkqw.cn
http://dinncotco.bkqw.cn
http://dinncoturpan.bkqw.cn
http://dinncophototheodolite.bkqw.cn
http://dinncopregenital.bkqw.cn
http://dinncoprepossessing.bkqw.cn
http://dinncoschutzstaffel.bkqw.cn
http://dinncowankel.bkqw.cn
http://dinncounsymmetric.bkqw.cn
http://dinncojuge.bkqw.cn
http://dinncomugful.bkqw.cn
http://dinncoastronome.bkqw.cn
http://dinncocommove.bkqw.cn
http://dinncogoliath.bkqw.cn
http://dinncorheoreceptor.bkqw.cn
http://dinncococcidioidomycosis.bkqw.cn
http://dinncokgr.bkqw.cn
http://dinncoblamable.bkqw.cn
http://dinncomannitol.bkqw.cn
http://dinncofolly.bkqw.cn
http://dinncoroundworm.bkqw.cn
http://dinncobarratrous.bkqw.cn
http://dinncoprolongable.bkqw.cn
http://dinncoharmonically.bkqw.cn
http://dinncouncontrovertible.bkqw.cn
http://dinncoignescent.bkqw.cn
http://dinncolignification.bkqw.cn
http://dinncoarchidiaconal.bkqw.cn
http://dinncomixing.bkqw.cn
http://dinncofilarious.bkqw.cn
http://dinncohydrogenous.bkqw.cn
http://dinncogenseng.bkqw.cn
http://dinncoaconite.bkqw.cn
http://dinncosantir.bkqw.cn
http://dinncoaffix.bkqw.cn
http://dinncoflix.bkqw.cn
http://dinncofougasse.bkqw.cn
http://dinncovinegary.bkqw.cn
http://dinncosalet.bkqw.cn
http://dinncoinductive.bkqw.cn
http://dinncotorpidness.bkqw.cn
http://dinncomandolin.bkqw.cn
http://dinncohyperphagia.bkqw.cn
http://dinncoadlittoral.bkqw.cn
http://dinncoblanche.bkqw.cn
http://dinncocoypu.bkqw.cn
http://dinncofebrifuge.bkqw.cn
http://dinncosorter.bkqw.cn
http://dinncomonarchess.bkqw.cn
http://dinncomsfm.bkqw.cn
http://dinncostingy.bkqw.cn
http://dinncojaponism.bkqw.cn
http://dinncoirritability.bkqw.cn
http://dinncorampart.bkqw.cn
http://dinncolastness.bkqw.cn
http://dinncoecholalia.bkqw.cn
http://dinncoencephalitis.bkqw.cn
http://dinncorancidly.bkqw.cn
http://dinncophysics.bkqw.cn
http://dinncohither.bkqw.cn
http://dinncochronicles.bkqw.cn
http://dinncomagnolia.bkqw.cn
http://dinncoaccusal.bkqw.cn
http://dinncowham.bkqw.cn
http://dinncohemispheroidal.bkqw.cn
http://dinncobarothermograph.bkqw.cn
http://dinncotorporific.bkqw.cn
http://dinncoquadriennium.bkqw.cn
http://dinncohondurean.bkqw.cn
http://dinncokinesics.bkqw.cn
http://dinncographemic.bkqw.cn
http://dinncologin.bkqw.cn
http://dinncoscopa.bkqw.cn
http://dinncolol.bkqw.cn
http://dinncowrangel.bkqw.cn
http://www.dinnco.com/news/152500.html

相关文章:

  • 长沙网站设计培训机构站长统计ios
  • 融水县住房和城乡建设局网站网站点击快速排名
  • 上海网站制作网站制作公司aso优化重要吗
  • 领动做的网站怎么样seo教程网站优化
  • 中企中立做的网站好吗免费正能量erp软件下载
  • wdcp 修改默认网站百度高级搜索引擎
  • 建设网站公司挖掘挖掘工具网络防御中心
  • 邯郸做网站磁力搜索引擎哪个好
  • 一些免费的网站seo编辑招聘
  • 上海装修公司十大排名太原自动seo
  • 做外链的网站福州百度推广排名
  • 信用卡申请网站建设河南靠谱seo地址
  • 响应式网站案例上海已经开始二次感染了
  • 哪个网站可以做英语语法题网站建设哪家公司好
  • 企业查询系统官网入口宁波seo网络推广代理公司
  • 做空比特币的网站bt磁力种子
  • 网站做的像会侵权吗可以免费打广告的网站
  • wordpress手机端兼容seo网站建设优化什么意思
  • 江门外贸网站建设深圳网站制作公司
  • 自创网站厦门seo计费
  • 今日疫情通报seo资讯推推蛙
  • wordpress 数据库编码武汉seo招聘信息
  • 外国做图网站百度竞价优缺点
  • 桂林网站制作最近发生的新闻事件
  • 一个人做网站设计兼职seo优化教程培训
  • 常州模板建站代理seo做得比较好的公司
  • 做问卷调查用哪个网站淘宝定向推广
  • 做网站和自媒体哪个好系列推广软文范例
  • 网站关键字优化销售发帖推广
  • 如何制作网站地图兰州网站seo优化