Skip to content

bst remove root node fix. bst specs. - #47

Merged
mgechev merged 1 commit into
mgechev:masterfrom
JakeHP:master
Feb 24, 2015
Merged

mgechev merged 1 commit into
mgechev:masterfrom
JakeHP:master

Conversation

@JakeHP

@JakeHP JakeHP commented Feb 24, 2015

Copy link
Copy Markdown
Collaborator

Issue here:
#46
Fix:

if (node._parent !== null) { // change - make sure parent is not null before replacing child
  if (node._left) {
    this._replaceChild(node._parent, node, node._left);
  } else if (node._right) {
    this._replaceChild(node._parent, node, node._right);
  } else {
    this._replaceChild(node._parent, node, null);
  }
}else {
  this._root = null; // if the parent is null, we are removing root, therefore assign null to root
}

Also added several basic tests.
And fixes some of the method comments so doc generation is correct.

@mgechev

mgechev commented Feb 24, 2015

Copy link
Copy Markdown
Owner

Thanks! I guess I missed this base case...

Everything looks alright, merging.

mgechev added a commit that referenced this pull request Feb 24, 2015
bst remove root node fix. bst specs.
@mgechev
mgechev merged commit b6662ef into mgechev:master Feb 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants