Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

avl-tree.js: deleting root value deletes the tree by setting root to undefined #115

Open
@jmb20

Description

@jmb20

Theremove function of the AVL tree appears to delete the entire tree by setting the root property of the tree toundefined if the root value is removed.

This is because the function's callthis.root = balanceUpstream( node.parent ); has parameternode.parent = null ifnode is the root (see commented out function call below). FunctionbalanceUpstream will then immediately returnundefined whichremove assigns tothis.root deleting the tree.

I have fixed this in my implementation of avl-tree.js using a ternary operator:

remove( value ) {        const node = super.find( value );        if ( node ) {            const found = super.remove( value );            const parent = node.parent ? node.parent : this.root;            this.root = balanceUpstream( parent );            //this.root = balanceUpstream( node.parent );            return found;        }        return false;    }

Posted as a (potential) issue as I am not sure whether this is an issue only in my implementation which differs somewhat from the one in this repository.

Cheers!

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp