Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Tree
- {
- ExpressionTreeNode root;
- }
- class leaf extends Tree
- {
- String numbervalue;
- public leaf(String expr)
- {
- this.numbervalue = expr;
- }
- }
- class Expr extends Tree
- {
- Tree left, right;
- String operation;
- List<String> listofstrings;
- public Expr(String operation, Tree left, Tree right, List<String> stringlist)
- {
- this.operation = operation;
- this.left = left;
- this.right = right;
- this.listofstrings = stringlist;
- }
- }
- List<String> listofstrings; // input
- public Tree makeBinaryTree(List<String> listofstrings)
- {
- String element = listofstrings.get(0);
- Tree left, right;
- //Expr newexpr = new Expr(element, left, right, listofstrings);
- if(isanumber(element))
- {
- return new leaf(element);
- }
- else
- {
- left = makeBinaryTree(listofstrings);
- right = makeBinaryTree(listofstrings);
- }
- listofstrings = removefirst(listofstrings);
- return new Expr(element, left, right, listofstrings);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement