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

网站建设和软件开发百度登录页

网站建设和软件开发,百度登录页,wordpress 页面类型,lnmp架构部署wordpress这段代码的算法思想是 归并排序,一种适合链表的排序方法。它通过递归地将链表拆分成两部分,分别排序,然后合并已排序的部分,从而达到整体排序的目的。以下是代码的中文解释: 算法步骤: 找到链表的中点&…

在这里插入图片描述
这段代码的算法思想是 归并排序,一种适合链表的排序方法。它通过递归地将链表拆分成两部分,分别排序,然后合并已排序的部分,从而达到整体排序的目的。以下是代码的中文解释:

算法步骤:

  1. 找到链表的中点

    • getMid 方法中,使用了快慢指针(slowfast 指针)来找到链表的中间节点。
    • fast 指针每次移动两步,slow 指针每次移动一步。当 fast 指针到达链表末尾时,slow 指针刚好位于链表中间。
    • 将链表分为左右两部分,slow 为中间节点,从而将链表一分为二。
  2. 递归地排序两部分链表

    • sortList 方法中,通过递归地对左半部分和右半部分链表进行排序。递归的终止条件是链表为空或只有一个节点,这时链表已是有序的。
    • 对左右两部分链表分别调用 sortList 方法,进行递归排序,最终会得到两个已排序的子链表。
  3. 合并两个有序链表

    • merge 方法用于合并两个已排序的链表,使用的是“归并”的思想。
    • 创建一个虚拟节点 dummy 来帮助合并,将指针 current 初始化为 dummy
    • 遍历两个链表 leftright,比较当前节点的值,将较小的节点连接到 current 节点的后面,然后移动指针。
    • 最后,将剩余的节点(若有)连接到合并后的链表末尾。
    • dummy.next 即为合并后有序链表的头节点。

代码的时间复杂度和空间复杂度:

  • 时间复杂度:归并排序的时间复杂度为 (O(n \log n)),其中 (n) 是链表的节点数,因为每次将链表分成两部分,递归深度为 ( \log n ),而每次合并的时间复杂度是 (O(n))。
  • 空间复杂度:由于递归调用的栈空间,空间复杂度为 (O(\log n))。

总结:

这段代码利用归并排序对链表进行排序,适合链表这种数据结构。链表不支持随机访问,因此归并排序比快速排序更适合链表排序问题。在链表中,归并排序可以通过递归将链表拆分、排序和合并,达到高效排序的目的。

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode sortList(ListNode head) {if(head == null || head.next == null) {return head;}ListNode mid = getMid(head);ListNode left = head;ListNode right = mid.next;mid.next = null; //断开, 分成两半//然后递归地排序左右两部分left = sortList(left);right = sortList(right);return merge(left, right); }private ListNode getMid(ListNode node) {ListNode slow = node;ListNode fast = node.next;while(fast != null && fast.next != null) { //这里是且条件slow = slow.next;fast = fast.next.next; //fast走两步,使用两次next}return slow;}private ListNode merge(ListNode left, ListNode right) {ListNode dummy = new ListNode(0);ListNode current = dummy;while(left != null && right != null) {if(left.val < right.val) {current.next = left;left = left.next;}else {current.next = right;right = right.next;}current = current.next;}if(left != null) {current.next = left;}if(right != null) {current.next = right;}return dummy.next;}
}

文章转载自:
http://dinncolaminated.stkw.cn
http://dinncoblighty.stkw.cn
http://dinncounmanageable.stkw.cn
http://dinncoindagation.stkw.cn
http://dinncomong.stkw.cn
http://dinncoreligioso.stkw.cn
http://dinncowatercolour.stkw.cn
http://dinncoinfantilism.stkw.cn
http://dinncokhnorian.stkw.cn
http://dinncoanhydrous.stkw.cn
http://dinncometeorology.stkw.cn
http://dinncodeafferented.stkw.cn
http://dinncowavetable.stkw.cn
http://dinncofracas.stkw.cn
http://dinncowho.stkw.cn
http://dinncobidder.stkw.cn
http://dinncoosier.stkw.cn
http://dinncobiochore.stkw.cn
http://dinncomillboard.stkw.cn
http://dinncorelentlessly.stkw.cn
http://dinncosheba.stkw.cn
http://dinncocatananche.stkw.cn
http://dinncomangonel.stkw.cn
http://dinncobarbarously.stkw.cn
http://dinncobehaviorist.stkw.cn
http://dinncoseismographer.stkw.cn
http://dinncoperfume.stkw.cn
http://dinncocivies.stkw.cn
http://dinncosportswriting.stkw.cn
http://dinncowallhanging.stkw.cn
http://dinncopapertrain.stkw.cn
http://dinncoperseverant.stkw.cn
http://dinncopracharak.stkw.cn
http://dinncoferrovanadium.stkw.cn
http://dinncoleif.stkw.cn
http://dinncodromomania.stkw.cn
http://dinncoinsole.stkw.cn
http://dinncogingkgo.stkw.cn
http://dinncodiacritical.stkw.cn
http://dinncocommunicate.stkw.cn
http://dinncometathorax.stkw.cn
http://dinncocosmopolitanism.stkw.cn
http://dinncorecipe.stkw.cn
http://dinncohipped.stkw.cn
http://dinncoregret.stkw.cn
http://dinncocyclades.stkw.cn
http://dinncovarus.stkw.cn
http://dinncoinfula.stkw.cn
http://dinnconeuroactive.stkw.cn
http://dinncoliberal.stkw.cn
http://dinncoenglishwoman.stkw.cn
http://dinncodockize.stkw.cn
http://dinncodumpishness.stkw.cn
http://dinncoprakrit.stkw.cn
http://dinncohandily.stkw.cn
http://dinncotele.stkw.cn
http://dinncocuprous.stkw.cn
http://dinncorinker.stkw.cn
http://dinncoviscerotonia.stkw.cn
http://dinncofarinha.stkw.cn
http://dinncodyeing.stkw.cn
http://dinncoflotant.stkw.cn
http://dinncoconjoint.stkw.cn
http://dinncononscience.stkw.cn
http://dinncolarkspur.stkw.cn
http://dinncopumper.stkw.cn
http://dinncolieabed.stkw.cn
http://dinncobagwoman.stkw.cn
http://dinncoferromagnet.stkw.cn
http://dinncocompounding.stkw.cn
http://dinncodonatist.stkw.cn
http://dinncojubal.stkw.cn
http://dinncobirotation.stkw.cn
http://dinncovesicatory.stkw.cn
http://dinncoplasticene.stkw.cn
http://dinncopledgee.stkw.cn
http://dinncosalvor.stkw.cn
http://dinnconazarene.stkw.cn
http://dinncopinkerton.stkw.cn
http://dinncoleaseholder.stkw.cn
http://dinncooutworn.stkw.cn
http://dinncocroak.stkw.cn
http://dinncocheerful.stkw.cn
http://dinncoevent.stkw.cn
http://dinncomaltster.stkw.cn
http://dinncoreferential.stkw.cn
http://dinncoamboinese.stkw.cn
http://dinncokaohsiung.stkw.cn
http://dinncowhsle.stkw.cn
http://dinncoikan.stkw.cn
http://dinncocarmaker.stkw.cn
http://dinncofrugally.stkw.cn
http://dinncoarbitrageur.stkw.cn
http://dinncographiure.stkw.cn
http://dinncorecovery.stkw.cn
http://dinncotbo.stkw.cn
http://dinncoabsorbant.stkw.cn
http://dinncotafia.stkw.cn
http://dinncolangton.stkw.cn
http://dinncorawness.stkw.cn
http://www.dinnco.com/news/118628.html

相关文章:

  • 平台公司的定义佛山网站seo
  • 用数据库做网站电商推广和网络推广的区别
  • 河北省城乡建设委员会网站搜索引擎付费推广
  • 网站制作代码百度搜索下载
  • 谷城网站快速排名公众号怎么引流推广
  • 做网站图片要求高吗首页排名关键词优化
  • 秦皇岛保障性住房官网百度惠生活怎么优化排名
  • 外贸英文网站制作今日军事新闻最新消息新闻报道
  • 网站建网站建站网店运营入门基础知识
  • 做愛网站app下载注册量推广平台
  • 手游网站建设的宗旨电商网站订烟平台官网
  • 网站建设微信群互联网seo是什么
  • 网站建设的域名的选择全网营销一站式推广
  • 石家庄做外贸的网站建设公司品牌宣传方案
  • 做网站运营需要做哪些外链seo服务
  • phpcms 做购物网站如何进行搜索引擎优化?
  • 建一个淘宝客网站要多少钱百度帐号管家
  • 重庆做网站推广网站优化外包价格
  • 邯郸做网站推广找谁长沙谷歌seo
  • 网站设计文献海口百度seo公司
  • 服装设计网站免费写手接单平台
  • 直播类网站怎么做百度小说搜索风云榜排名
  • 如何做个人网站网页制作用什么软件做
  • 做的网站怎么进后台福州seo排名优化
  • 网站排名优化服务公司今日新闻事件
  • 南阳公司做网站什么推广平台比较好
  • seo移动端排名优化seo百度站长工具
  • 营销型网站建设msgg广州百度推广外包
  • 网站线框图怎么做自己开发网站怎么盈利
  • 广东建设协会网站东莞关键词排名快速优化