-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUndirectedGraph.java
More file actions
63 lines (47 loc) · 1.46 KB
/
UndirectedGraph.java
File metadata and controls
63 lines (47 loc) · 1.46 KB
1
package socialnetwork;import Graph.GraphInterface;import Graph.StackInterface;/** A class that implements the ADT undirected graph. @author Frank M. Carrano @author Timothy M. Henry @version 4.0*/public class UndirectedGraph<T> extends DirectedGraph<T> implements GraphInterface<T>{ public UndirectedGraph() { super(); } // end default constructor public boolean addEdge(T begin, T end, double edgeWeight) { return super.addEdge(begin, end, edgeWeight) && super.addEdge(end, begin, edgeWeight); // Assertion: edge count is twice its correct value due to calling addEdge twice } // end addEdge public boolean addEdge(T begin, T end) { return this.addEdge(begin, end, 0); } // end addEdge // This function removes edges public boolean removeEdge(T begin, T end) { boolean result = false; super.removeEdge(begin, end); super.removeEdge(end, begin); return result; } public int getNumberOfEdges() { return super.getNumberOfEdges() / 2; } // end getNumberOfEdges public StackInterface<T> getTopologicalOrder() { throw new UnsupportedOperationException("Topological sort illegal in an undirected graph."); } // end getTopologicalOrder // this function adds vertex public boolean addVertex(T vertex) { return super.addVertex(vertex); } } // end UndirectedGraph// To make addEdge more efficient, DirectedGraph needs to provide accessors // to its data fields. (See Project 3, Chapter 29.)