-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartialTree.java
More file actions
62 lines (54 loc) · 1.26 KB
/
PartialTree.java
File metadata and controls
62 lines (54 loc) · 1.26 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
package structures;
public class PartialTree {
/**
* The root of the partial tree
*/
private Vertex root;
/**
* The arcs included in this partial tree
*/
private MinHeap<Arc> arcs;
/**
* Initializes this partial tree with given vertex
*
* @param vertex Vertex used to initialize the tree
*/
public PartialTree(Vertex vertex) {
root = vertex;
arcs = new MinHeap<Arc>();
}
/**
* Merges another partial tree into this partial tree
*
* @param other The partial tree to be merged with this tree.
*/
public void merge(PartialTree other) {
other.root.parent = root;
arcs.merge(other.arcs);
}
/**
* Returns the root of this tree.
*
* @return Root of tree
*/
public Vertex getRoot() {
return root;
}
/**
* Returns the priority-ordered arc set of this tree. The lower the weight of an arc,
* the higher its priority.
*
* @return Priority-ordered arc set.
*/
public MinHeap<Arc> getArcs() {
return arcs;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
String ret = "Vertices: " + root.toString();
ret += " PQ: " + arcs;
return ret;
}
}