Skip to content
Snippets Groups Projects
Commit c5b53a95 authored by kraleva's avatar kraleva
Browse files

cleanup

parent 61d67ed7
No related branches found
No related tags found
1 merge request!29IterativeSCC
......@@ -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>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment