Skip to content

Maybe there are some redundent code in Doubly-Linked-List #655

@ten-ltw

Description

@ten-ltw
    reverse() {
        let node = this.head,
            previous = null,
            next = null;

        while (node) {
            next = node.next;
            console.log(previous?.value);
            previous = node.previous;
            console.log(previous?.value);
            node.next = previous;            
            node.previous = next;

            previous = node;
            node = next;
        }
        this.tail = this.head;
        this.head = previous;
        return this;
    }

I think the code previous = node.previous; in while loop is redundent code. I try this code and the previous.vaule always get a same value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions