Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. abstract class Tree
  2. {
  3. ExpressionTreeNode root;
  4. }
  5.  
  6. class leaf extends Tree
  7. {
  8. String numbervalue;
  9.  
  10. public leaf(String expr)
  11. {
  12. this.numbervalue = expr;
  13. }
  14. }
  15.  
  16.  
  17. class Expr extends Tree
  18. {
  19. Tree left, right;
  20. String operation;
  21. List<String> listofstrings;
  22.  
  23. public Expr(String operation, Tree left, Tree right, List<String> stringlist)
  24. {
  25. this.operation = operation;
  26. this.left = left;
  27. this.right = right;
  28. this.listofstrings = stringlist;
  29. }
  30. }
  31.  
  32. List<String> listofstrings; // input
  33.  
  34. public Tree makeBinaryTree(List<String> listofstrings)
  35. {
  36. String element = listofstrings.get(0);
  37. Tree left, right;
  38. //Expr newexpr = new Expr(element, left, right, listofstrings);
  39.  
  40. if(isanumber(element))
  41. {
  42. return new leaf(element);
  43. }
  44. else
  45. {
  46. left = makeBinaryTree(listofstrings);
  47. right = makeBinaryTree(listofstrings);
  48. }
  49. listofstrings = removefirst(listofstrings);
  50. return new Expr(element, left, right, listofstrings);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement