[英]LEVEL BY LEVEL of a Tree with Java
How can I get all the elements of a Tree? 如何获得树的所有元素?
public static <E> PositionList<E> width(Tree<E> t){
//I've initialized a queue and a PositionList<E>
Queue<E> aux = new NodeQueue<E>();
PositionList<E> positionAux = new NodePositionList<E>();
Position<E> pointer = t.root();
... ...
but then I don't know how to continue... 但是我不知道该如何继续...
Example: 例:
1
| |
2 3
| | | |
4 5 6 7
Return a list [1,2,3, 4, 5, 6, 7] 返回列表[1,2,3,4,5,6,7]
Use a Queue to do level traverse. 使用队列进行水平遍历。 You can see my implementation: https://github.com/shaogbi/Java/blob/master/datastructure/MyBinaryTree.java see
levelTraverse
function. 您可以看到我的实现: https : //github.com/shaogbi/Java/blob/master/datastructure/MyBinaryTree.java参见
levelTraverse
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.