SOURCE

class Node{
    constructor(val){
        this.val = val
        this.next = null
    }
}

class LinkList{
    constructor(){
        this.head = null
        this.length = 0
    }

    add(val){
        let node = new Node(val)
        if(this.head == null){
            this.head = node
            this.length++
        }else{
            let current = this.head
            while(current.next){
                current = current.next
            }
            current.next = node
            this.length++
        }

    }
}


let list1 = new LinkList()

list1.add(1)
list1.add(2)
list1.add(3)
list1.add(4)



let list2 = new LinkList()


list2.add(5)
list2.add(6)
list2.add(7)
list2.add(8)

// console.log(list1,list2)


const rankLink =function(l1,l2){
    if(!l1){
        return l2
    }
    if(!l2){
        return l1
    }
    if(l1.val < l2.val){
        // l1.next = rankLink(l1.next,l2)
        l1.next = arguments.callee(l1.next,l2)
        return l1
    }else{
         l1.next = arguments.callee(l2.next,l1)
        // l2.next = rankLink(l2.next,l1)
        return l2
    }
}


// console.log(rankLink(list1.head,list2.head))


//

class Queue{
    constructor(payload){
        this.payload = payload
        this.nextNode = null
    }
}


class ListQueue{
    constructor(){
        this.firstNode = null
        this.lastNode =null
        this.initState = {}
    }

    enqueue(queue){
        if(this.firstNode ==null){
            this.firstNode = this.lastNode =queue
        }else{
            this.lastNode.nextNode = queue
            this.lastNode = queue
        }
    }

    forceUpdate(){
        let current = this.firstNode
        let currentState = this.initState
        while(current){
            let updateState = typeof current.payload =='function'?current.payload(currentState):current.payload
            currentState ={...currentState,...updateState
            }
            current = current.nextNode
        }
        return currentState
    }
}


let listQueue =new ListQueue()


listQueue.enqueue(new Queue({num:1}))
listQueue.enqueue(new Queue({num:2}))
listQueue.enqueue(new Queue((state)=>{state.num++}))
listQueue.enqueue(new Queue({id:5}))


console.log(listQueue,listQueue.forceUpdate())

console 命令行工具 X clear

                    
>
console