I am implementing a tree class from scratch, I have data fields and constructor like below: public class TreeNode implements Node{ int data; TreeNode child; TreeNode parent; String name; Boolean visited;
public TreeNode(int data){
this.data = data;
child = null;
parent = null;
name = null;
visited = false;
}
one of the method I need to implement is getChildren(Node n), which returns a list that contains all children of Node n. I have no idea about how to find all children of nodes. thank you for your help!
public List<Node> getChildren() {
List<Node> children = new ArrayList<>();
while(!children.contains(this.child)){
children.add(this.child);}
return children;
}