我真的很想知道是否存在任何技术或算法来执行此操作。
PS:倒退旅行应该是不可能的。 它应该适用于 n 否: 的级别
传递一个集合来存储所有节点遍历后序,并在到达最低点时打印。
void printPathsRecur(Node node, int path[], int pathLen)
{
if (node == null)
return;
/* append this node to the path array */
path[pathLen] = node.data;
pathLen++;
/* it's a leaf, so print the path that led to here */
if (all node for the parrent is null)
printArray(path, pathLen);
else
{
for(int i=0;i<node.getChildLenth();i++){
printPathsRecur(node.child[i], path, pathLen);
}
}