Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Joshua
- */
- public class NumericBinaryTree {
- private NumericBinaryTree root;
- private NumericBinaryTree leftChild;
- private NumericBinaryTree rightChild;
- private Number rootValue;
- /**
- * Constructor that will create an empty numeric
- * binary tree.
- * @param
- */
- public NumericBinaryTree() {
- this.root = null;
- this.leftChild = null;
- this.rightChild = null;
- }
- /**
- * Constructor that will create a numeric binary tree with
- * a value.
- * @param takes a value of type number and sets it as the
- * root of the tree
- */
- public NumericBinaryTree(Number rootValue) {
- if (rootValue == null) {
- throw new IllegalArgumentException("");
- }
- this.rootValue = rootValue;
- this.root = root;
- System.out.println("this is the root value" + rootValue);
- System.out.println("this is the root of the tree " + root);
- }
- /**
- * Constructor that will create a binary tree with a value and
- * its left and right child.
- *
- * @param takes a value of type number and sets it as the
- * root of the tree. Takes a tree for its left child and right
- * child.
- */
- public NumericBinaryTree(Number rootValue, NumericBinaryTree leftChild,
- NumericBinaryTree rightChild) {
- if (rootValue == null) {
- throw new IllegalArgumentException("");
- }
- this.rootValue = rootValue;
- this.root = root;
- this.leftChild = leftChild;
- this.rightChild = rightChild;
- System.out.println("in a tree with children whose root value is" + rootValue);
- }
- /**
- * Check to see if the tree is empty.
- *
- * @param
- */
- public boolean isEmpty() {
- return root == null;
- }
- }
- public class NumericBinaryTreeTest {
- public static void main(String[] args) {
- Number a = 0;
- Number b = 1;
- Number c = 2;
- Number d = 3;
- NumericBinaryTree emptyTree = new NumericBinaryTree();
- NumericBinaryTree treeWithAValue = new NumericBinaryTree(a);
- NumericBinaryTree treeWithChildren = new NumericBinaryTree(b, emptyTree,
- treeWithAValue);
- System.out.println(treeWithAValue.isEmpty());
- System.out.println(emptyTree.isEmpty());
- System.out.println(treeWithChildren.isEmpty());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement