Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WGraph.java E8WGraph.java No Selection 1 import java.io.* 2 import java.util.* 3 class Edge( public int) nodes new int[2]; /The nodes connected by the edges/ public

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
WGraph.java E8WGraph.java No Selection 1 import java.io.* 2 import java.util.* 3 class Edge( public int) nodes new int[2]; /The nodes connected by the edges/ public Integer weight; /*Integer so we can use Comparator*/ Edge(int i, int j, int w) this.nodes[e)i; this.nodes(1] j this.weightw; 10 12 14 public class WGraph( 15 16 17 18 19 20 21 private ArrayList edges = new ArrayList(); private ArrayList nodesnew ArrayList private int nb_nodes 8 private Integer source; private Integer destination 0; WGraph) WGraph(WGraph graph) 26 for(Edge e:graph.edges) this.addEdge(new Edge(e.nodes[),e.nodes[1),e.weight)); this.source -graph.source; this.destinationgraph.destination; 30 31 WGraph (String file) throws RuntimeException ( try f Scanner f new Scanner(new File (file)); String) ln-f.nextLine().split("+ I*first line is the source and destinations/ this.sourceInteger.parseInt(Inte]) this.destination-Integer.parseInt(n1]) int number nodesInteger.parseInt(f.nextLine)) /second line is the number of nodes*/ 35 38 while (f.hasNext)) String) line f.nextline).split("\s+) /*Make sure there is 3 elements on the line/ if (line.length 3) continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions