(int vertex)
| 22 | |
| 23 | // DFS algorithm |
| 24 | void DFS(int vertex) { |
| 25 | visited[vertex] = true; |
| 26 | System.out.print(vertex + " "); |
| 27 | |
| 28 | Iterator<Integer> ite = adjLists[vertex].listIterator(); |
| 29 | while (ite.hasNext()) { |
| 30 | int adj = ite.next(); |
| 31 | if (!visited[adj]) |
| 32 | DFS(adj); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public static void main(String args[]) { |
| 37 | Graph g = new Graph(4); |