I am using DefaultMutableTreeNode to perform an operation in tree. The root is a multiply sign and the two children are integers. The tree is built, here are a few operations and their outputs:
System.out.println("get first child:” +root.getFirstChild());
Output for the above is:
the value of the root and children will print with no problem, but I can’t use an inequality with them such as this:
get first child: 5
…because root.getRoot() is a TreeNode type and ‘*’ is a char
for my application, the root is either going to be a +, -, *, or / sign, and the two children will be integers. I would like to use a switch or if statements to match the root node value to one of the 4 operators. any idea how to change or cast the value of a TreeNode to the value of a character type?
The end result is: If the left child has the value 5, the right child has the value 4, and the root is an ‘*’ sign, then the answer would be 20