Does anyone know how to traverse a binary search tree using loops instead of recursion?
I have the recursive method
public static int countMatches(BinaryNodeInterface<Integer> tree, Integer key)
{
int matches = 0;
if (tree != null)
{
if (tree.getData().equals(key))
matches++;
matches += countMatches(tree.getLeftChild(), key);
matches += countMatches(tree.getRightChild(), key);
}
return matches;
}