Question: I would like this code debugged with the following solution where to insert these in my code proposed solution public LinkedList getIncidentEdgeList ( ) {

I would like this code debugged with the following solution where to insert these in my code
proposed solution
public LinkedList getIncidentEdgeList(){ return incidentEdgeList; }
public String getName(){ return this.name; }
code
import java.util.*;
public class SimpleGraph {
LinkedList vertexList;
LinkedList edgeList;
// Constructor
public SimpleGraph(){
this.vertexList = new LinkedList();
this.edgeList = new LinkedList();
}
/**
* Return the vertex list of this graph.
* @returns vertex list of this graph
*/
public Iterator vertices(){
return vertexList.iterator();
}
/**
* Return the edge list of this graph.
* @returns edge list of this graph
*/
public Iterator edges(){
return edgeList.iterator();
}
/**
* Given a vertex, return an iterator to the edge list of that vertex
* @param v a vertex
* @returns an iterator to the edge list of that vertex
*/
public Iterator incidentEdges(Vertex v){
return v.incidentEdgeList.iterator();
}
/**
* Return an arbitrary vertex of this graph
* @returns some vertex of this graph
*/
public Vertex aVertex(){
if (vertexList.size()>0)
return (Vertex) vertexList.getFirst();
else
return null;
}
Error
public class SimpleGraph {
LinkedList vertexList;
LinkedList edgeList;
// Constructor
public SimpleGraph(){
this.vertexList = new LinkedList();
this.edgeList = new LinkedList();
}
/**
* Return the vertex list of this graph.
* @returns vertex list of this graph
*/
public Iterator vertices(){
return vertexList.iterator();
}
/**
* Return the edge list of this graph.
* @returns edge list of this graph
*/
public Iterator edges(){
return edgeList.iterator();
}
/**
* Given a vertex, return an iterator to the edge list of that vertex
* @param v a vertex
* @returns an iterator to the edge list of that vertex
*/
public Iterator incidentEdges(Vertex v){
return v.incidentEdgeList.iterator();
}
/**
* Return an arbitrary vertex of this graph
* @returns some vertex of this graph
*/
public Vertex aVertex(){
if (vertexList.size()>0)
return (Vertex) vertexList.getFirst();
else
return null;
}
/**
* Add a vertex to this graph.
* @param data an object to be associated with the new vertex
* @param name a name to be associated with the new vertex
* @returns the new vertex
*/
public Vertex insertVertex(Object data, Object name){
Vertex v;
v = new Vertex(data, name);
vertexList.addLast(v);
return v;
}
/**
* Add an edge to this graph.
* @param v the first endpoint of the edge
* @param w the second endpoint of the edge
* @param data data to be associated with the new edge
* @param name name to be associated with the new edge
* @returns the new edge
*/
public Edge insertEdge(Vertex v, Vertex w, Object data, Object name){
Edge e;
e = new Edge(v, w, data, name);
edgeList.addLast(e);
v.incidentEdgeList.addLast(e);
w.incidentEdgeList.addLast(e);
return e;
}
/**
* Given a vertex and an edge, if the vertex is one of the endpoints
* of the edge, return the other endpoint of the edge. Otherwise,
* return null.
* @param v a vertex
* @param e an edge
* @returns the other endpoint of the edge (or null, if v is not an endpoint of e)
*/
public Vertex opposite(Vertex v, Edge e){
Vertex w;
if (e.getFirstEndpoint()== v){
w= e.getSecondEndpoint();
}
else if (e.getSecondEndpoint()== v){
w = e.getFirstEndpoint();
}
else
w = null;
return w;
}
/**
* Return the number of vertices in this graph.
* @returns the number of vertices
*/
public int numVertices(){
return vertexList.size();
}
/**
* Return the number of edges in this graph.
* @returns the number of edges
*/
public int numEdges(){
return edgeList.size();
}
/**
* Code to test the correctness of the SimpleGraph methods.
*/
public static void main(String[] args){
// create graph a----b-----c,
// X Y
// X and Y are objects stored at edges. .
// All Objects stored will be strings.
SimpleGraph G = new SimpleGraph();
Vertex v, w, a, b, c;
Edge e, x, y;
v = G.insertVertex(null,"a");
a = v;
w = G.insertVertex(null,"b");
b = w;
e = G.insertEdge(v, w, null, "X");
x = e;
v = G.insertVertex(null,"c");
c = v;
e = G.insertEdge(w, v, null, "Y");
y = e;
Iterator i;
System.out.println("Iterating through vertices...");
for (i= G.vertices(); i.hasNext(); ){
v =(Vertex) i.next();
System.out.println("found vertex "+ v.getName());
}
System.out.println("Iterating through adjacency lists...");
for (i= G.vertices(); i.hasNext(); ){
v =(Vertex) i.next();
System.out.println("Vertex "+v.getName());
Iterator j;
for (j = G.incidentEdges(v); j.hasNext();){
e =(Edge) j.next();
System.out.println(" found edge "+ e.getName());
}
}
System.out.println("Testing opposite...");
System.out.println("aXbYc is ");
System.out.println(a);
System.out.println(x);
System.out.println(b);
System.out.println(y);
System.out.println(c);
System.out.println(
error
scalingFordFulksersonAlgorithm: build failed At 11/22/21 sec,25 msSimpleGraph
I would like this code debugged with the

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 Programming Questions!