import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;

public class DepthFirstTraversal {

    // Array  of lists for Adjacency List Representation
    public static LinkedList<Integer>[] adj;

    //Function to add an edge into the DepthFirstTraversal
    private static void addEdge(int v, int w) {
        adj[v].add(w);
    }

    // A function used by DFS
    private static void depthFirstTraversal(int v, Set visited) {
        // Mark the current node as visited 
        visited.add(v);
        System.out.println(v);
        Iterator<Integer> i = adj[v].listIterator();
        while (i.hasNext()) {
            int n = i.next();
            if (!visited.contains(n)) {
                depthFirstTraversal(n, visited);
            }
        }
    }

    public static void dfs(int v) {
        // false by default in java)
        Set<Integer> visited = new HashSet();
        // Call the recursive helper function to print DFS traversal
        depthFirstTraversal(v, visited);
    }

    public static void initEdges(int n) {
        adj = new LinkedList[n];
        for (int i = 0; i < n; ++i) {
            adj[i] = new LinkedList();
        }
    }

    public static void main(String[] args) {
        initEdges(4);
        addEdge(0, 1);
        addEdge(0, 2);
        addEdge(1, 2);
        addEdge(2, 0);
        addEdge(2, 3);
        addEdge(3, 0);
        System.out.println("Depth First Traversal starting from vertex 2");
        dfs(2);
    }
}

@@ -97,16 +97,45 @@
 il.Set;%0A
+import java.util.ArrayList;%0A%0A
 %0Apublic 
@@ -179,18 +179,12 @@
 rray
-  of l
+L
 ist
-s
  for
@@ -232,16 +232,26 @@
  static 
+ArrayList%3C
 LinkedLi
@@ -261,18 +261,17 @@
 Integer%3E
-%5B%5D
+%3E
  adj;%0A%0A 
@@ -275,16 +275,17 @@
 %0A%0A    //
+ 
 Function
@@ -388,19 +388,23 @@
      adj
-%5Bv%5D
+.get(v)
 .add(w);
@@ -495,16 +495,25 @@
 t v, Set
+%3CInteger%3E
  visited
@@ -653,11 +653,15 @@
  adj
-%5Bv%5D
+.get(v)
 .lis
@@ -968,16 +968,25 @@
  HashSet
+%3CInteger%3E
 ();%0A    
@@ -1162,21 +1162,40 @@
 new 
-LinkedList%5Bn%5D
+ArrayList%3CLinkedList%3CInteger%3E%3E()
 ;%0A  
@@ -1249,14 +1249,13 @@
  adj
-%5Bi%5D = 
+.add(
 new 
@@ -1264,17 +1264,27 @@
 nkedList
-(
+%3CInteger%3E()
 );%0A     

fix DepthFirstTraversal.java warnings #274