Find the deepest node in the binary tree

Code

BinaryTreeNode deepestNodeInBinaryTree(BinaryTreeNo de root)
{
    
    
  BinaryTreeNode temp;
  LLQueue q = new LLQueue();
  if(root == null)
    return null;
   q.enqueue(root);
   while(!q.isEmpty()){
    
    
     temp = q.deQueue();
     if(temp.getLeft() != null){
    
    
       q.enQueue(temp.getLeft());
     }
     if(temp.getRight() != null){
    
    
       q.enQueue(temp.getRight());
     }
   }
   q.deleteQueue();
   return temp;

}

Guess you like

Origin blog.csdn.net/weixin_37632716/article/details/110826226