Make DFS and BFS search algorithms generic (fixes #4229) (#4230)

This commit is contained in:
Snir Turgeman
2023-08-13 09:29:26 +03:00
committed by GitHub
parent 1ef700e850
commit 18848574be
6 changed files with 245 additions and 86 deletions

View File

@ -0,0 +1,32 @@
package com.thealgorithms.datastructures;
import java.util.ArrayList;
import java.util.List;
public class Node<T> {
private final T value;
private final List<Node<T>> children;
public Node(final T value) {
this.value = value;
this.children = new ArrayList<>();
}
public Node(final T value, final List<Node<T>> children) {
this.value = value;
this.children = children;
}
public T getValue() {
return value;
}
public void addChild(Node<T> child) {
children.add(child);
}
public List<Node<T>> getChildren() {
return children;
}
}