xsnippet logotype

xsnippet

#363001, Untitled [ Java ]

by Guest
 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
import java.util.ArrayList;
import java.util.List;

public class Node {
private List<Node> children = new ArrayList<Node>();
private Node parent = null;
private Node data = null;

public Node(Node data) {
    this.data = data;
}

public Node(Node data, Node parent) {
    this.data = data;
    this.parent = parent;
}

public List<Node> getChildren() {
    return children;
}

public void setParent(Node parent) {
    this.parent = parent;
}

public void addChild(Node data) {
    Node child = new Node(data);
    child.setParent(this);
    this.children.add(child);
}


public void removeParent() {
    this.parent = null;
}
}