6. This is from laboratory 15. For the ALGraph.java complete the method that we
ID: 3579285 • Letter: 6
Question
6. This is from laboratory 15. For the ALGraph.java complete the method that we discussed for maxDegree().
import java.util.*;
import java.io.*;
@SuppressWarnings("unchecked")
public class ALGraph
{
String fileName="Graph.txt";
ArrayList<Integer>[] graph;
int size =1000000;
public ALGraph() {
graph = new ArrayList[size];
//edges = new HashSet<String>();
for (int i=0;i<size;i++)
graph[i] = new ArrayList<Integer>();
}
/* public void printEdgeList() {
Iterator<Integer> p = null;
for (int i=0;i<size;i++) {
p=graph[i].iterator();
while(p.hasNext()) {
int j=p.next();
if (i<j) System.out.println(i+" "+j);
}
}
}
*/
// prints the vertex number with the maximum number of adjacent vertices and the number of edges incident on it.
// For example, if a graph has three vertices 0,1,2 with number of edges incident on vertex 0 being 2, being incident on vertex 1 being 1, and being incident on vertex 2 being 1,
//then you will output vertex 0 has max degree 2.
public void maxDegree() {
}
public void readGraph() {
Scanner fileScanner;
try
{
fileScanner = new Scanner (new File (fileName));
while (fileScanner.hasNext()) {
String word = fileScanner.nextLine();
String[] edge = word.split(",");
int p = Integer.parseInt(edge[0]);
int q= Integer.parseInt(edge[1]);
graph[p].add(q);
graph[q].add(p);
//convert edge string after splitting into integers
}
}
catch (IOException e)
{
System.out.println(e);
}
}
public static void main(String[] args) {
ALGraph g = new ALGraph();
g.readGraph();
// g.printEdgeList();
}
}
Explanation / Answer
I can provide you the solution for the code, but I just want to confirm that i need to add or remove parameters to the function calls in order to make the code run properly.
I will give you the link to the code compiled by me in the comment. feel free to ask if you have any doubt :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.