Question: In the class GraphAlgorithm, insert java code for the method prim public class MyGraph { public static final int MAXSIZE = 100; public static final

In the class GraphAlgorithm, insert java code for the method prim
public class MyGraph {
public static final int MAXSIZE = 100;
public static final double BIGM = 10000000;
public MyGraph(int size) {
n = size;
nodeStart = new Edge[MAXSIZE];
for (int i=0; i
nodeStart[i] = null;
}
}
public int getSize() {
return n;
}
public double getCost(int i, int j) {
double value = BIGM;
Edge e = nodeStart[i];
while (e !=null) {
if (e.dest == j) value = e.cost;
e=e.next;
}
return value;
}
public void setCost(int i, int j, double c) {
Edge e = nodeStart[i];
boolean found = false;
while (e !=null && !found) {
if (e.dest == j) {
e.cost = c;
found = true;
}
else e=e.next;
}
if (!found) insertEdge(i,j,c);
}
public void insertEdge(int i, int j, double c) {
deleteEdge(i,j);
Edge ins = new Edge(i,j,c);
ins.next = nodeStart[i];
nodeStart[i] = ins;
}
public void deleteEdge(int i, int j) {
boolean found = false;
Edge prev = null;
Edge e = nodeStart[i];
if (e != null) {
if (e.dest == j) {
found = true;
nodeStart[i] = e.next;
}
else {
prev = e;
e = e.next;
}
}
while (e != null && !found) {
if (e.dest == j) {
found = true;
prev.next = e.next;
}
else {
prev = e;
e = e.next;
}
}
}
public MyGraph copy() {
MyGraph result = new MyGraph(n);
Edge e = first();
while (!this.eol()) {
result.insertEdge(e.orig, e.dest, e.cost);
e = next();
}
return result;
}
public Edge first() {
int currNode = 0;
currentLoc = nodeStart[currNode];
while (currentLoc == null && currNode
currentLoc = nodeStart[++currNode];
}
return currentLoc;
}
public boolean eol() {
return (currentLoc == null);
}
public Edge next() {
if (!eol()) {
int currNode = currentLoc.orig;
currentLoc = currentLoc.next;
while (currentLoc == null && currNode
currNode++;
currentLoc = nodeStart[currNode];
}
return currentLoc;
}
else return null;
}
private int n;
private Edge[] nodeStart;
private Edge currentLoc;
}
 In the class GraphAlgorithm, insert java code for the method prim
public class MyGraph { public static final int MAXSIZE = 100; public
static final double BIGM = 10000000; public MyGraph(int size) { n =
public class Edge { public Edge(int i, int j, double c) orig-i; dest-ji cost Ci public int orig; public int dest; public double cost; public Edge next - null

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!