diff --git a/mapbuilder/src/main/java/map/builder/utilities/ConnectedComponentGraph.java b/mapbuilder/src/main/java/map/builder/utilities/ConnectedComponentGraph.java index 5fb920c981e4b3778d973f09a280d5726a668153..d59b858940b1477f32e5937f755c5d16e6b32f82 100644 --- a/mapbuilder/src/main/java/map/builder/utilities/ConnectedComponentGraph.java +++ b/mapbuilder/src/main/java/map/builder/utilities/ConnectedComponentGraph.java @@ -28,41 +28,7 @@ public class ConnectedComponentGraph { adj.get(v).add(w); } - // A recursive function to print DFS starting from v - public ArrayList<Long> DFSUtil(Long v, HashMap<Long, Boolean> visited) { - // Mark the current node as visited and print it - visited.put(v, true); - - ArrayList<Long> component = new ArrayList<Long>(); - Long n; - - // Recur for all the vertices adjacent to this vertex - Iterator<Long> i = adj.get(v).iterator(); - while (i.hasNext()) { - n = i.next(); - if (!visited.get(n)) - component = DFSUtil(n, visited, component); - } - component.add(v); - return component; - } - - public ArrayList<Long> DFSUtil(Long v, HashMap<Long, Boolean> visited, ArrayList<Long> list) { - // Mark the current node as visited and print it - visited.put(v, true); - Long n; - - // Recur for all the vertices adjacent to this vertex - Iterator<Long> i = adj.get(v).iterator(); - while (i.hasNext()) { - n = i.next(); - if (!visited.get(n)) - DFSUtil(n, visited, list); - } - list.add(v); - return list; - } - + // iterative function for calculating DFS public ArrayList<Long> DFS(Long s, HashMap<Long, Boolean> visited) { // Create a stack for DFS Stack<Long> stack = new Stack<Long>(); @@ -117,23 +83,6 @@ public class ConnectedComponentGraph { return g; } - public void fillOrder(Long v, HashMap<Long, Boolean> visited, Stack<Long> stack) { - // Mark the current node as visited and print it - visited.put(v, true); - - // Recur for all the vertices adjacent to this vertex - Iterator<Long> i = adj.get(v).iterator(); - while (i.hasNext()) { - Long n = i.next(); - if (!visited.get(n)) - fillOrder(n, visited, stack); - } - - // All vertices reachable from v are processed by now, - // push v to Stack - stack.push(v); - } - public void fillOrderIterative(Long v, HashMap<Long, Boolean> visited, Stack<Long> stack) { // Create a stack for filling Stack<Long> helperStack = new Stack<Long>();