Adjacency list represention of graph in Java
Here is the program for adjacency list representation of graphs using java. If you are new to Graphs please read about graphs here before reading the rest of this post.
Code:
package com.vaani.algo.graph.impl; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class GraphUsingAdjList { class Node { int node; List<Integer> adjList; boolean visited; } void insertVertices() throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter number of nodes in a graph: "); int n=(Integer.
[Read More]