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 incidentEdgesVertex v
return vincidentEdgeList.iterator;
Return an arbitrary vertex of this graph
@returns some vertex of this graph
public Vertex aVertex
if vertexListsize
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 incidentEdgesVertex v
return vincidentEdgeList.iterator;
Return an arbitrary vertex of this graph
@returns some vertex of this graph
public Vertex aVertex
if vertexListsize
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 insertVertexObject data, Object name
Vertex v;
v new Vertexdata name;
vertexList.addLastv;
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 insertEdgeVertex v Vertex w Object data, Object name
Edge e;
e new Edgev w data, name;
edgeList.addLaste;
vincidentEdgeList.addLaste;
wincidentEdgeList.addLaste;
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 oppositeVertex v Edge e
Vertex w;
if egetFirstEndpoint v
w egetSecondEndpoint;
else if egetSecondEndpoint v
w egetFirstEndpoint;
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 mainString args
create graph abc
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 GinsertVertexnulla;
a v;
w GinsertVertexnullb;
b w;
e GinsertEdgev w null, X;
x e;
v GinsertVertexnullc;
c v;
e GinsertEdgew v null, Y;
y e;
Iterator i;
System.out.printlnIterating through vertices...";
for i Gvertices; ihasNext;
v Vertex inext;
System.out.printlnfound vertex vgetName;
System.out.printlnIterating through adjacency lists...";
for i Gvertices; ihasNext;
v Vertex inext;
System.out.printlnVertex vgetName;
Iterator j;
for j GincidentEdgesv; jhasNext;
e Edge jnext;
System.out.println found edge egetName;
System.out.printlnTesting opposite...";
System.out.printlnaXbYc is ;
System.out.printlna;
System.out.printlnx;
System.out.printlnb;
System.out.printlny;
System.out.printlnc;
System.out.println
error
scalingFordFulksersonAlgorithm: build failed At sec msSimpleGraph
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
