From c5b53a95986ba212ceb2a8a2fde8769836f4cc04 Mon Sep 17 00:00:00 2001 From: kraleva <viktoriakraleva@gmail.com> Date: Tue, 4 Apr 2023 13:11:30 +0200 Subject: [PATCH] cleanup --- .../utilities/ConnectedComponentGraph.java | 53 +------------------ 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/mapbuilder/src/main/java/map/builder/utilities/ConnectedComponentGraph.java b/mapbuilder/src/main/java/map/builder/utilities/ConnectedComponentGraph.java index 5fb920c..d59b858 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>(); -- GitLab