hi.. i have a binary search tree class which is a user defined one.. when i invoke the deepNode method some sort of logic error occur...
the tree structure is :
Uploaded with ImageShack.us
the code of the deepNode is:
public void deepNode() { if (isEmpty())return; Queue2 q= new Queue2(); q.enqueue(root); while (!q.isEmpty()) { BTNode cur=(BTNode) (q.dequeue()); if (cur!=null) { if (cur.left!=null) q.enqueue(cur.left); if (cur.right!=null) q.enqueue(cur.right); if (cur.right==null && cur.left==null) System.out.println(cur.item); } } }
the current output is: 23, 21
the correct output should be: 21