V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kssdxw
V2EX  ›  问与答

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

  •  
  •   kssdxw · Feb 23, 2019 · 1004 views
    This topic created in 2626 days ago, the information mentioned may be changed or developed.

    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
       Feb 23, 2019
    emmm,问题忽然解决了,我甚至不知道为什么,抱歉打扰……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2515 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 08:27 · PVG 16:27 · LAX 01:27 · JFK 04:27
    ♥ Do have faith in what you're doing.