Results 1 to 1 of 1
Thread: DefaultMutableTreeNode
- 03-02-2010, 04:15 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 31
- Rep Power
- 0
DefaultMutableTreeNode
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:
Java Code:System.out.println("Root: "+root.getRoot()); 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:Java Code:Root: * get first child: 5
…because root.getRoot() is a TreeNode type and ‘*’ is a charJava Code:if(root.getRoot()== ‘*’)
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


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks