Datasets:

ArXiv:
License:
File size: 1,233 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
    }

}