diff --git a/Algoritmi_2/Laboratorio/Lab4/src/BFSAndDFSApp.java b/Algoritmi_2/Laboratorio/Lab4/src/BFSAndDFSApp.java index 42f70ab14fcf63b87d85810d5c760fe87a6e0fc3..73d6498fe1a839bb7fc9c3643d4558836a054f01 100644 --- a/Algoritmi_2/Laboratorio/Lab4/src/BFSAndDFSApp.java +++ b/Algoritmi_2/Laboratorio/Lab4/src/BFSAndDFSApp.java @@ -4,7 +4,8 @@ import it.uniupo.graphLib.UndirectedGraph; import java.util.Arrays; import java.util.ArrayList; -public class BFSAndDFSApp { +public +class BFSAndDFSApp { private GraphInterface myGraph; private BFS bfs; private DFS dfs; @@ -13,7 +14,8 @@ public class BFSAndDFSApp { private int[] fathers; GraphInterface treeDFS; - public BFSAndDFSApp(GraphInterface g) { + public + BFSAndDFSApp(GraphInterface g) { myGraph = g; BFS bfs = new BFS(g); DFS dfs = new DFS(g); @@ -23,7 +25,8 @@ public class BFSAndDFSApp { Arrays.fill(this.fathers, -1); } - private boolean visitaDFS(int sorg) { + private + boolean visitaDFS(int sorg) { if (sorg >= this.myGraph.getOrder() || sorg < 0) { throw new IllegalArgumentException("Sorgente non presenten nel grafo"); } @@ -40,7 +43,8 @@ public class BFSAndDFSApp { return false; } - public boolean hasUndirectedCycle() { + public + boolean hasUndirectedCycle() { for (int nodo = 0; nodo < this.myGraph.getOrder(); nodo++) { if (visitaDFS(nodo)) { return true; @@ -49,7 +53,8 @@ public class BFSAndDFSApp { return false; } - private void visitaDFSPostVisit(int sorg, ArrayList<Integer> orderPostVisit) { + private + void visitaDFSPostVisit(int sorg, ArrayList<Integer> orderPostVisit) { if (sorg >= this.myGraph.getOrder() || sorg < 0) { throw new IllegalArgumentException("Sorgente non presenten nel grafo"); } @@ -62,13 +67,15 @@ public class BFSAndDFSApp { orderPostVisit.add(sorg); } - public ArrayList<Integer> getNodesInOrderPostVisit(int sorg) { + public + ArrayList<Integer> getNodesInOrderPostVisit(int sorg) { ArrayList<Integer> orderPostVisit = new ArrayList<>(); visitaDFSPostVisit(sorg, orderPostVisit); return orderPostVisit; } - private boolean hasDirCycleImpl(int sorg) { + private + boolean hasDirCycleImpl(int sorg) { scoperti[sorg] = true; for (Integer node : myGraph.getNeighbors(sorg)) { if (!scoperti[node]) { @@ -81,13 +88,16 @@ public class BFSAndDFSApp { return false; } - public boolean hasDirCycle() { + public + boolean hasDirCycle() { if (myGraph instanceof UndirectedGraph) { throw new IllegalArgumentException("Impossibile usare hasDirCycle su un grafo non orientato"); } for (int i = 0; i < myGraph.getOrder(); i++) { fathers = new int[myGraph.getOrder()]; + Arrays.fill(fathers, -1); scoperti = new boolean[myGraph.getOrder()]; + Arrays.fill(scoperti, false); if (hasDirCycleImpl(i)) { return true; }