-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBSTexercise.java
79 lines (67 loc) · 2.36 KB
/
BSTexercise.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
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
import java.io.*;
import java.util.Scanner;
public class BSTexercise
{
public static void main ( String[] args ) throws FileNotFoundException
{
Comparable tmp;
Double tmpDouble;
java.util.Scanner console = new java.util.Scanner(System.in);
Scanner readA1 = new Scanner(new FileReader("C:\\input\\inputA1.txt"));
Scanner readA2 = new Scanner(new FileReader("C:\\input\\inputA2.txt"));
Scanner readB1 = new Scanner(new FileReader("C:\\input\\inputB1.txt"));
Scanner readB2 = new Scanner(new FileReader("C:\\input\\inputB2.txt"));
BinarySearchTree treeA1 = new BinarySearchTree("i");
BinarySearchTree treeA2 = new BinarySearchTree("d");
BinarySearchTree treeB1 = new BinarySearchTree("i");
BinarySearchTree treeB2 = new BinarySearchTree("d");
treeA1.makeEmpty();
treeA2.makeEmpty();
treeB1.makeEmpty();
treeB2.makeEmpty();
while (readA1.hasNext())
treeA1.insert(readA1.nextInt());
while (readA2.hasNext())
treeA2.insert(readA2.nextDouble());
/*
while (readB1.hasNext())
treeB1.insert(readB1.nextInt());
while (readB2.hasNext())
treeB2.insert(readB2.nextDouble());
*/
System.out.print("TreeA1 \n In-Order: ");
System.out.println(treeA1.printTree());
treeA1.findMax();
treeA1.findMin();
System.out.print("TreeA2 \n In-Order: ");
System.out.println(treeA2.printTree());
treeA2.findMax();
treeA2.findMin();
/*
System.out.print("TreeB1 \n In-Order: ");
System.out.println((treeB1.printTree()));
treeB1.findMax();
treeB1.findMin();
System.out.print("TreeB2 \n In-Order: ");
System.out.println(treeB2.printTree());
treeB2.findMax();
treeB2.findMin();
*/
System.out.println("\nRemoving keys in TreeB1.txt from TreeA1");
while (readB1.hasNext())
{
tmp = readB1.nextInt();
if (treeA1.contains(tmp))
treeA1.delete(tmp);
}
System.out.println(treeA1.printTree());
System.out.println("\nRemoving keys in TreeB2.txt from TreeA2");
while (readB2.hasNext())
{
tmpDouble = readB2.nextDouble();
if (treeA2.contains(tmpDouble))
treeA2.delete(tmpDouble);
}
System.out.println(treeA2.printTree());
}
}