I have to make a model of this arithmetical expression using a binary tree. Expression is a+b*c-b
http://piccy.info/view3/7176082/d09578d27ea7057c572de3f108a9301f/
Here's the model of my tree in Java
enum NodeType { NUMBER, OPERATOR } // Possible kinds of node.
class ExpNode { // A node in an expression tree.
NodeType kind; // Which type of node is this?
double number; // The value in a node of type NUMBER.
char op; // The operator in a node of type OPERATOR.
ExpNode left; // Pointers to subtrees,
ExpNode right; // in a node of type OPERATOR.
ExpNode( double val ) {
// Constructor for making a node of type NUMBER.
kind = NodeType.NUMBER;
number = val;
}
ExpNode( char op, ExpNode left, ExpNode right ) {
// Constructor for making a node of type OPERATOR.
kind = NodeType.OPERATOR;
this.op = op;
this.left = left;
this.right = right;
}
}
I don't know how to implement an insert method for adding a nodes. After that I will have to print the tree in console and change nodes for making this expression (a+b)*c-b Help me please, I'm not strong in Java