Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tree 如何在不使用递归的情况下在C中找到二叉树的高度?_Tree_Iteration_Binary Tree - Fatal编程技术网

Tree 如何在不使用递归的情况下在C中找到二叉树的高度?

Tree 如何在不使用递归的情况下在C中找到二叉树的高度?,tree,iteration,binary-tree,Tree,Iteration,Binary Tree,我可以在不使用递归的情况下获得C语言中二叉树的最大深度的逻辑。不使用递归的情况下获得树的高度是对树进行BFS(非递归)。并记录你正在达到的水平。最后一级的数字应该是你在树上的深度 上述方法的伪代码应如下所示: Q: Queue like data structure root: root of your tree couter = 0 // variable which will denote depth. 1. Q -> add ( root) 2. while ( Q is not e

我可以在不使用递归的情况下获得C语言中二叉树的最大深度的逻辑。

不使用递归的情况下获得树的高度是对树进行BFS(非递归)。并记录你正在达到的水平。最后一级的数字应该是你在树上的深度

上述方法的伪代码应如下所示:

Q: Queue like data structure
root: root of your tree
couter = 0 // variable which will denote depth.
1. Q -> add ( root)
2. while ( Q is not empty) 
2.1 size = Q-> size ();
  2.2 while( size -- > 0)
  2.2.1 Process your tree
  2.2.2 Increment: Counter 
  End of While (2.2)
End of While (2)