I said dfs, I used recursive programming. But I just could not make the code working, and I could not understand where to push/ pop the data from the stack in my implementation.
Utilisateur anonyme
4 mai 2015
It's similar to DFS!
public void printAllPaths(Node node, int[] path, int len) {
if (node == null)
return;
path[len] = node.mData;
len++;
if (node.mLeftNode == null && node.mRightNode == null) {
for (int i = 0; i < len; i++) {
System.out.print(path[i] + " ");
}
return;
}
printAllPaths(node.mLeftNode, path, len);
System.out.println();
printAllPaths(node.mRightNode, path, len);
}