/** Clear tree method * @param a node */ private void clear(Node x) { if(x.left != null) { x = x.left; clear(x); } if(x.right != null) { x = x.right; clear(x); } }
And relevant code fragment
Node iter = root.left; Node iter2 = root.right; // delete left side of tree while(iter != null) { clear(iter); System.out.println(""+iter.value); iter = iter.left; } // delete right side of tree while(iter2 != null) { clear(iter2); iter = iter.right; } // delete root clear(root); root = null;
Above code is supposed to delete an entire binary search tree. But I don't know if it's doing it right or not.
Sorry if it's been posted before. If it doesn't work could you point me in the right direction?
Thanks.


LinkBack URL
About LinkBacks
Reply With Quote