Published
- 1 min read
foreach not applicable to type - binary tree sort
The solution for this is noted below
foreach not applicable to type - binary tree sort
Solution
private static void iterateall(BinaryTree foo) {
Stack<BinaryTree> nodes = new Stack<BinaryTree>();
nodes.push(foo);
while (!nodes.isEmpty()) {
BinaryTree node = nodes.pop();
if (node == null)
continue;
System.out.println(node.node);
nodes.push(node.right);
nodes.push(node.left);
}
}
Try other methods by searching on the site. That is if this doesn’t work