diff --git a/BST.png b/BST.png new file mode 100644 index 0000000..0300642 Binary files /dev/null and b/BST.png differ diff --git a/src/Test/IntSetBSTTest.java b/src/Test/IntSetBSTTest.java new file mode 100644 index 0000000..7c698eb --- /dev/null +++ b/src/Test/IntSetBSTTest.java @@ -0,0 +1,56 @@ +package devSet; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Random; + +import org.junit.jupiter.api.Test; + +class IntSetBSTTest { + + IntSetBST bst = new IntSetBST(); + private static int MAX_VAL = 1000000; + private static int MAX_ELE = MAX_VAL/100; + private static Random num = new Random(); + + @Test + void testIntSetImp() { + bst.intSetImp(MAX_ELE, MAX_VAL); + assertEquals(MAX_VAL, bst.maxval); + assertEquals(MAX_ELE, bst.maxelems); + } + + @Test + void testInsert() { + + bst.intSetImp(MAX_ELE, MAX_VAL); + + int x =0; + for(int i=0;inewNode.data){ + p.left = insertKey(p.left, x); + return p; + } + else if(p.datap.data) p = p.right; + else return p; + } + return p; + } + + public void inorder(TreeNode root, ArrayList arr){ + if(this.root!=null){ + inorder(root.left, arr); + arr.add(root.data); + inorder(root.right, arr); + } + } + + public int[] inorder() { + int[] result = new int[this.size]; + ArrayList list = new ArrayList(); + this.inorder(this.root, list); + + for(int i=0; i maxelems) { + return ; + } + else if(element > maxval) { + return ; + } + bst.insertBST(element); + } + + @Override + public int size() { + // TODO Auto-generated method stub + return bst.getSize(); + } + + @Override + public int[] report() { + // TODO Auto-generated method stub + return bst.inorder(); + } + +} diff --git a/src/devSet/TreeNode.java b/src/devSet/TreeNode.java new file mode 100644 index 0000000..fe045d5 --- /dev/null +++ b/src/devSet/TreeNode.java @@ -0,0 +1,22 @@ +package devSet; + +public class TreeNode { + int data; + TreeNode left; + TreeNode right; + + public TreeNode(){ + this.left = null; + this.right = null; + } + + public TreeNode(int x){ + this.data = x; + this.left = null; + this.right = null; + } + + public Object getData(){ + return data; + } +} \ No newline at end of file