Datasets:
ArXiv:
License:
Download data/train/MrWe/bioAI/task2/src/BFS.java from RepoFusion/Stack-Repo: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/MrWe/bioAI/task2/src/BFS.java
- Command line
-
hf download hf://datasets/RepoFusion/Stack-Repo@bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/MrWe/bioAI/task2/src/BFS.java
-
curl -L -o BFS.java https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/MrWe/bioAI/task2/src/BFS.java
1.23 kB
| import java.util.ArrayList; | |
| import java.util.HashSet; | |
| import java.util.LinkedList; | |
| import java.util.concurrent.ExecutorService; | |
| import java.util.concurrent.Executors; | |
| public class BFS { | |
| public static ArrayList<Segment> BFS(ArrayList<Node> rootnodes) { | |
| final ArrayList<Segment> segments = new ArrayList<>(); | |
| final HashSet<Node> seen = new HashSet<>(); | |
| for (int n = 0; n < rootnodes.size(); n++) { | |
| final int index = n; | |
| final LinkedList<Node> children = new LinkedList<>(); | |
| segments.add(new Segment()); | |
| children.add(rootnodes.get(index)); | |
| while (!children.isEmpty()) { | |
| final Node current = children.remove(0); | |
| segments.get(index).add(current); | |
| segments.get(index).setRootNode(current); | |
| current.setSegment(segments.get(index)); | |
| for (final Node child : current.getChildren()) { | |
| if (child.isRoot() || seen.contains(child)) { | |
| continue; | |
| } | |
| children.add(child); | |
| seen.add(child); | |
| } | |
| } | |
| } | |
| return segments; | |
| } | |
| } | |