forked from dblandin/Binary-Search-Tree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSTTest.java
More file actions
executable file
·96 lines (83 loc) · 3.68 KB
/
BSTTest.java
File metadata and controls
executable file
·96 lines (83 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Devon Blandin
* Assignment 3 :: CSC383 (SSII)
* August 4th, 2012
*/
public class BSTTest
{
public static void main(String[] args)
{
System.out.println("\nTesting with Integers");
// create binary search tree for Integers
// BinarySearchTree()
BinarySearchTree<Integer> tree = new BinarySearchTree<Integer>();
// add integers
// add(T value)
System.out.println("\nAdding 20 random integers to tree");
for (int i = 0; i < 20; i++)
{
int randomNumber = (int) (Math.random() * 100 - 50 + 1);
tree.add(randomNumber);
}
// print tree
// print()
System.out.println("\nPrinting tree");
tree.print();
// check contains method
// contains(T value)
for (int i = 0; i < 10; i++)
{
int randomNumber = (int) (Math.random() * 100 - 50 + 1);
System.out.println("Does tree contain " + randomNumber + "? : " + tree.contains(randomNumber));
}
// getMax()
System.out.println("Tree Max: " + tree.getMax()); // check getMax
// getMin()
System.out.println("Tree Min: " + tree.getMin()); // check getMin
// getDepth()
System.out.println("Tree Depth: " + tree.getDepth()); // check getDepth
// getNumLeaves()
System.out.println("Number of leaves: " + tree.getNumLeaves()); // check getNumLeaves
// print it sideways
// printSideways()
System.out.println("---------- Printing Sideways ------------");
tree.printSideways();
System.out.println("\nTesting with Strings");
// String letter array to populate binary search tree with
String[] letters = { "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" };
// create binary search tree for Strings
// BinarySearchTree()
BinarySearchTree<String> tree2 = new BinarySearchTree<String>();
// add letters
// add()
System.out.println("\nAdding 20 random letters to tree");
for (int i = 0; i < 20; i++)
{
int randomNumber = (int) (Math.random() * letters.length);
tree2.add(letters[randomNumber]);
}
// print tree
// print()
System.out.println("\nPrinting tree");
System.out.println(tree2);
// check contains method
// contains(T value)
for (int i = 0; i < 10; i++)
{
int randomNumber = (int) (Math.random() * letters.length);
System.out.println("Does tree contain " + letters[randomNumber] + "? " + tree2.contains(letters[randomNumber]));
}
// getMax()
System.out.println("Tree Max: " + tree2.getMax()); //check getMax
// getMin()
System.out.println("Tree Min: " + tree2.getMin()); // check getMin
// getDepth()
System.out.println("Tree Depth: " + tree2.getDepth()); // check getDepth
// getNumLeaves()
System.out.println("Number of leaves: " + tree2.getNumLeaves()); // check getNumLeaves
// print it sideways
// printSideways()
System.out.println("---------- Printing Sideways ------------");
tree2.printSideways();
} // end main
} // end BSTTest