Advertisement
Guest User

NumericBinaryTree

a guest
Feb 11th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. /**
  8. *
  9. * @author Joshua
  10. */
  11. public class NumericBinaryTree {
  12.  
  13. private NumericBinaryTree root;
  14. private NumericBinaryTree leftChild;
  15. private NumericBinaryTree rightChild;
  16. private Number rootValue;
  17.  
  18. /**
  19. * Constructor that will create an empty numeric
  20. * binary tree.
  21. * @param
  22. */
  23. public NumericBinaryTree() {
  24. this.root = null;
  25. this.leftChild = null;
  26. this.rightChild = null;
  27. }
  28.  
  29. /**
  30. * Constructor that will create a numeric binary tree with
  31. * a value.
  32. * @param takes a value of type number and sets it as the
  33. * root of the tree
  34. */
  35. public NumericBinaryTree(Number rootValue) {
  36. if (rootValue == null) {
  37. throw new IllegalArgumentException("");
  38. }
  39. this.rootValue = rootValue;
  40. this.root = root;
  41. System.out.println("this is the root value" + rootValue);
  42. System.out.println("this is the root of the tree " + root);
  43. }
  44.  
  45. /**
  46. * Constructor that will create a binary tree with a value and
  47. * its left and right child.
  48. *
  49. * @param takes a value of type number and sets it as the
  50. * root of the tree. Takes a tree for its left child and right
  51. * child.
  52. */
  53.  
  54. public NumericBinaryTree(Number rootValue, NumericBinaryTree leftChild,
  55. NumericBinaryTree rightChild) {
  56. if (rootValue == null) {
  57. throw new IllegalArgumentException("");
  58. }
  59. this.rootValue = rootValue;
  60. this.root = root;
  61. this.leftChild = leftChild;
  62. this.rightChild = rightChild;
  63.  
  64. System.out.println("in a tree with children whose root value is" + rootValue);
  65. }
  66.  
  67. /**
  68. * Check to see if the tree is empty.
  69. *
  70. * @param
  71. */
  72. public boolean isEmpty() {
  73. return root == null;
  74. }
  75. }
  76. public class NumericBinaryTreeTest {
  77.  
  78.  
  79. public static void main(String[] args) {
  80. Number a = 0;
  81. Number b = 1;
  82. Number c = 2;
  83. Number d = 3;
  84.  
  85. NumericBinaryTree emptyTree = new NumericBinaryTree();
  86.  
  87. NumericBinaryTree treeWithAValue = new NumericBinaryTree(a);
  88.  
  89. NumericBinaryTree treeWithChildren = new NumericBinaryTree(b, emptyTree,
  90. treeWithAValue);
  91.  
  92. System.out.println(treeWithAValue.isEmpty());
  93. System.out.println(emptyTree.isEmpty());
  94. System.out.println(treeWithChildren.isEmpty());
  95. }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement