Question
Graph.java import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedList; import java.util.StringTokenizer; /* * To change this template,
Graph.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.StringTokenizer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
public class Graph {
public int V;
public int E;
public LinkedList
public Graph()
{
V = 0;
E = 0;
}
public Graph(BufferedReader reader) throws IOException
{
String line;
line = reader.readLine();
V = Integer.parseInt(line);
line = reader.readLine();
E = Integer.parseInt(line);
adj = new LinkedList[V];
for (int v = 0; v
adj[v] = new LinkedList
}
while ((line = reader.readLine()) != null) {
int tempV1, tempV2;
StringTokenizer st = new StringTokenizer(line, " ");
tempV1 = Integer.parseInt(st.nextToken());
tempV2 = Integer.parseInt(st.nextToken());
addEdge(tempV1, tempV2);
}
}
public void addEdge(int v, int w) {
}
public String tostring()
{
String s = new String();
s = "There are "+V+" vertices and "+E+" edges ";
for(int i=0;i { s = s+i+": "; for(int j = 0; j { s = s+adj[i].get(j)+" "; } s = s+" "; } return s; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started