Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class GraphServices {
- public static <V> void bfs(Graph<V> g) {
- Collection<Node<V>> nodi_grafo = new LinkedList<>();
- nodi_grafo = g.getNodes();
- for (Node<V> s : nodi_grafo) {bfsAux(g, s);}
- return;
- }
- private static <V> void bfsAux(Graph<V> g, Node<V> s) {
- ArrayDeque<Node<V>> livello = new ArrayDeque<>();
- if (s.stato != Node.Stato.EXPLORED) {
- s.stato = Node.Stato.EXPLORED;
- System.out.println(s);
- }
- livello.addLast(s);
- while (!livello.isEmpty()) {
- ArrayDeque<Node<V>> nuovoLivello = new ArrayDeque<>();
- for (Node<V> u : livello) {
- for (Edge<V> e : g.getOutEdges(u)) {
- Node<V> v = e.getTarget();
- if (v.stato != Node.Stato.EXPLORED) {
- v.stato = Node.Stato.EXPLORED;
- System.out.println(v.getElement());
- nuovoLivello.addLast(v);
- }
- }
- }
- livello = nuovoLivello;
- }
- return;
- }
- public static <V> void sssp(Graph<V> g, Node<V> source) {
- }
- public static <V> void mst(Graph<V> G) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement