-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWolfvilleTester.java
59 lines (47 loc) · 2.24 KB
/
WolfvilleTester.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
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class WolfvilleTester {
public static void main(String[] args) {
//
PruferCode code = new PruferCode(new ArrayList<>(List.of(2, 1, 0, 5, 2, 7, 0)));
TreeNode root = code.getTreeRoot();
String adjString = root.adjMatrixToString();
File dir = new File("examples");
if (!dir.exists()) {
dir.mkdir();
}
try (java.io.PrintWriter out = new java.io.PrintWriter("examples/wolfville.txt")) {
out.print(adjString);
}
catch (java.io.FileNotFoundException e) {
System.out.println("File not found.");
}
System.out.println(adjString);
//
TreeNode nodeFour = root.findDescendant(4);
int distanceRootToRoot = root.distanceFrom(root);
int distanceFourToFour = nodeFour.distanceFrom(nodeFour);
int distanceRootToFour = root.distanceFrom(nodeFour);
System.out.println("Distance from root to root: " + distanceRootToRoot);
System.out.println("Distance from node 4 to node 4: " + distanceFourToFour);
System.out.println("Distance from root to node 4: " + distanceRootToFour);
//
TreeNode nodeZero = root.findDescendant(0);
TreeNode nodeFive = root.findDescendant(5);
int distanceZeroToFive = nodeZero.distanceFrom(nodeFive);
int distanceFourToFive = nodeFour.distanceFrom(nodeFive);
System.out.println("Distance from node 0 to node 5: " + distanceZeroToFive);
System.out.println("Distance from node 4 to node 5: " + distanceFourToFive);
//
TreeNode nodeTwo = root.findDescendant(2);
TreeNode nodeSix = root.findDescendant(6);
int distanceTwoToSix = nodeTwo.distanceFrom(nodeSix);
System.out.println("Distance from node 2 (root) to node 6: " + distanceTwoToSix);
//
TreeNode nodeOne = root.findDescendant(1);
TreeNode nodeThree = root.findDescendant(3);
int distanceOneToThree = nodeOne.distanceFrom(nodeThree);
System.out.println("Distance from node 1 to node 3: " + distanceOneToThree);
}
}