-
Notifications
You must be signed in to change notification settings - Fork 824
/
Main.java
42 lines (31 loc) · 1.14 KB
/
Main.java
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
import java.util.ArrayList;
import java.util.Random;
public class Main {
public static void main(String[] args) {
BST<Integer> bst = new BST<>();
Random random = new Random();
int n = 1000;
// test removeMin
for(int i = 0 ; i < n ; i ++)
bst.add(random.nextInt(10000));
ArrayList<Integer> nums = new ArrayList<>();
while(!bst.isEmpty())
nums.add(bst.removeMin());
System.out.println(nums);
for(int i = 1 ; i < nums.size() ; i ++)
if(nums.get(i - 1) > nums.get(i))
throw new IllegalArgumentException("Error!");
System.out.println("removeMin test completed.");
// test removeMax
for(int i = 0 ; i < n ; i ++)
bst.add(random.nextInt(10000));
nums = new ArrayList<>();
while(!bst.isEmpty())
nums.add(bst.removeMax());
System.out.println(nums);
for(int i = 1 ; i < nums.size() ; i ++)
if(nums.get(i - 1) < nums.get(i))
throw new IllegalArgumentException("Error!");
System.out.println("removeMax test completed.");
}
}