TestBST.java
Select all
/* TestBST.java CIS 260 Dave Klick 4/4/09 Test driver for BST.java (binary search tree class). This code includes the class Test which will be stored in the BST. */ class Test implements Comparable<Test> { private int num; public int compareTo(Test t) { return num - t.num; } Test(int n) { num = n; } public String toString() { return "" + num; } } public class TestBST { public static void main(String[] args) { BST<Test> tree = new BST<Test>(); int[] nums = { 50, 75, 89, 64, 100, 50, 92, 64, 27, 12, 64, 35 }; for (int i=0; i<nums.length; i++) { if (!tree.insert(new Test(nums[i]))) { System.out.println("Insert of " + nums[i] + " failed. Probably a duplicate value."); } } tree.inorder(); } }