I have this class
class Node {
Node parent;
int rank;
public Node() {
this.parent = this;
this.rank = 0;
}
}
I would like to create subclasses of Node
, but I want parent
to be the same type as it's corresponding type.
How can I do this?
Ultimately, I am trying to create a special UnionFind data structure. I implemented the find
and merge
functions for the data structures. However, I want to extend this and add more functionality. I would like to add the member V value
to Node
and record the minimum value of each set. For me, the best way to do this is to create a subclass of Node. Would there be a better way to this?