V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
kssdxw
V2EX  ›  问与答

前端用 Class 继承 Array 新建快排方法,结果无限递归,求大佬帮看看。

  •  
  •   kssdxw · 2019-02-23 22:39:05 +08:00 · 639 次点击
    这是一个创建于 1903 天前的主题,其中的信息可能已经有所发展或是发生改变。

    class MyArray extends Array{
    constructor(){
    super()
    }
    quicksort(left=0,right=this.length-1){
    if(left>right){
    return
    }
    let i = left
    let j =right
    let jizhun = this[left]
    while(i!=j){
    while(this[j]>=jizhun&j>i){j--}
    while(this[i]<=jizhun&j>i){i++}
    [this[i],this[j]]=[this[j],this[i]]
    }
    [this[left],this[i]]=[this[i],this[left]]
    this.quicksort(left,i-1)
    this.quicksort(i+1,right)
    }
    }

    这是代码,调用 quicksort()方法进行对自身的排序时就会无限递归跑崩浏览器,求大佬帮忙指点,问题出在哪。

    kssdxw
        1
    kssdxw  
    OP
       2019-02-23 22:45:33 +08:00
    emmm,问题忽然解决了,我甚至不知道为什么,抱歉打扰……
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3073 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.