How to delete the largest node in Binary search Tree -
i trying delete largest node in binary search tree, thougth these code below should able reason not. please!
public void remove() { node current = root; while(true){ node parent = current; current = current.getrighchild(); if (current == null){ parent.setrighchild(null); return; } } }
public void remove() { root = deletemax(root); } private node deletemax(node x ) { if (x.getrighchild() == null) { return x.getleftchild(); } x.setrighchild(deletemax(x.getrighchild())); return x;
}
Comments
Post a Comment