非递归算法查找二叉树的满结点个数

int numberOfFullNodesInBTusingLevelOrder(BinaryTreeNode root){
    
    
  BinaryTreeNode temp;
  LLQueue q.= new LLQueue();
  int count = 0;
  if(root == null)
    return count;
  q.enQueue(root);
  while(!q.isEmpty()){
    
    
    temp = q.deQueue();
    if(temp.getLeft()!=null&&temp.getRight()!=null){
    
    
    count++;
}
   if(temp.getleft()!=null){
    
    
     q.enQueue(temp.getLeft());
   }
   if(temp.getRight() !=null){
    
    
     q.enQueue(temp.getRight());
   }
  }
  q.deleteQueue();
  return count;
}

猜你喜欢

转载自blog.csdn.net/weixin_37632716/article/details/110984576