java - Binary Search Tree Remove method not working -
public class bstnode <e extends comparable<e>> { private e value; private bstnode<e> left; public bstnode<e> right; .... public bstnode<e>remove(e item) { if(item.equals(this.value)){ return replacementsubtreefromchildren(this.left, this.right); } if (item.compareto(this.value)<0){ this.left = this.left.remove(item); } else{this.right = this.right.remove(item); } return this; } private bstnode<e> replacementsubtreefromchildren(bstnode<e> left, bstnode<e> right) { if(left==null && right==null){ return null; } else if(left!=null && right==null){ return this.left; } else if(left==null && right!=null){ return this.right; } else{ e getleft=this.right.getleftmostnode().getvalue(); this.value = getleft; this.right = right.remove(getleft); } return this; } /** * returns leftmost node in subtree formed receiver. * * completion * * hint: code simple. keep descending left branches, * until no longer possible. * * @returns reference leftmost node, starting receiver. * */ private bstnode<e> getleftmostnode() { if (this.left == null) { return this; } else{ return this.left.getleftmostnode(); }
for reason method not remove tree. can me find why doing this?
i have tested , methods being accessed, suspect have pointer somewhere incorrectly cannot find where.
inst comp103 assignment 6 @ victoria university trimester
Comments
Post a Comment