Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There is only one error left. Please help correct the code below. Please do not copy other codes on other sites and place as answer.

 There is only one error left. Please help correct the code below. Please do not copy other codes on other sites and place as answer. This is the code that needs to be corrected. import java.io.*; public class GraphFileWriter { public void PrintSpanningTree (); public class GraphFileReader { private final String DELIMETER = "-"; private final int ROOT_NODE = 0; // this is starting point of the scan private ArrayList < Edge > spanningTree = new ArrayList < Edge > (); private NodeList nodeList; public GraphFileReader (NodeList list) { nodeList = list; for (Edge e;SpanningTree) { System.out.println ("(" + e.primaryNode () + "," + e.adjNode () + ") " + e.cost ()); } } public void Scan () { ArrayList < Integer > solutionNodes = new ArrayList < Integer > (); solutionNodes.add (ROOT_NODE); // kickstart the processing by adding the first node boolean done = false; while (!done) { // continue until we have no more edge costs left int newMinValue = Integer.MAX_VALUE; int newMinSourceNodeId = -1; int newMinDestNodeId = -1; // this is one scan of the graph to find all adjacents and select next solution node for (Integer u:solutionNodes) { // scan of current solution nodes ArrayList < Edge > adjacents = nodeList.GetAdjacents (u); for (Edge edge:adjacents) { int v = edge.adjNode (); // v is node number for this edge (first node is u) int cost = edge.cost (); // cost of edge from u->v if (!solutionNodes.contains (v)) { // this is an adjacent candidate node // scan adjacent nodes and keep track of costs, find min if (cost < newMinValue) { newMinValue = cost; newMinSourceNodeId = u; newMinDestNodeId = v; System.out.println (" Setting min " + u + "-->" + v + " cost=" + newMinValue); } } } } } if (newMinDestNodeId > -1) { // found a new node for solution System.out.println ("Solution: " + newMinDestNodeId + " cost=" + newMinValue); solutionNodes.add (newMinDestNodeId); // put latest one in the solution // put all new info into the final spanning tree Edge newEdge = new Edge (newMinSourceNodeId, newMinDestNodeId, newMinValue); spanningTree.add (newEdge); } else { done = true; } } // end main while loop } public void PrintSpanningTree () { System.out.println ("Spanning Tree"); System.out.println ("Edge Weight"); for (Edge e:spanningTree) { System.out.println ("(" + e.primaryNode () + "," + e.adjNode () + ") " + e.cost ()); } } } 

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Where was the declaration of independence signed?

Answered: 1 week ago