Estou tentando executar este método, mas sempre dar false na comparação. Assim não armazena os dados e não gera a saida desejada. Alguém sabe dizer como posso resolver este problema?
static Vector<Integer> list = new Vector<>();
// Function to find the nodes
// having single child
static void printNodesOneChild(Node root)
{
// Base case
if (root == null)
return;
// Condition to check if the node
// is having only one child
if (root.left != null && root.right == null ||
root.left == null && root.right != null)
{
list.add(root.data);
}
// Traversing the left child
printNodesOneChild(root.left);
// Traversing the right child
printNodesOneChild(root.right);
}