i trying implement deleteedge method simple , undirected graph, using adjacency list (but no container edges).
this deleteedge method far:
//deletes edge e graph. throws exception if edge e null. public void deleteedge(edge<v> e) throws graphexception{ if(e == null){ system.out.println("deleteedge"); throw new graphexception(); } vertex<v> endpoint1 = e.getendpoint1(); vertex<v> endpoint2 = e.getendpoint2(); edge<v> edge = new edge<v> (endpoint2,endpoint1); endpoint1.removeadjacent(e); endpoint2.removeadjacent(edge); edges--; }
i use method called removeadjacent, , removeadjacent supposed take edge, , remove adjacency list of vertex invoking method
removeadjacent:
//removes adjacent edge. throws exception if edge e not adjacent vertex. //all means check if in adjacency list particular vertex right? //and if it's not, means it's not adjacent vertex , throw exception? public void removeadjacent(edge<v> e) throws graphexception{ if(this.adjacency.contains(e)){ this.adjacency.remove(e); } else{ system.out.println("removeadjacent"); throw new graphexception(); } }
in order test it, insert vertices, insert edges, delete known edge endpoints u , v, , test see if u , v still adjacent. whenever run program, removeadjacent function throws exception, , found out exception thrown when do
endpoint2.removeadjacent(edge)
but isnt way supposed done? delete edge, need remove edge adjacency lists of both endpoints? know why cant remove edge, reverse of e, endpoint2?
thanks!
note: adjacency linkedlist structure filled part of class vertex adjacency stores edges adjacent object of vertex
possibly problem not remove, maybe add.
when adding edge between 2 vertex 1 not have right edge.
the other possibility equals of class edge or vertex.
Comments
Post a Comment