Interface DiGraph<T>
-
public interface DiGraph<T>
DiGraph.java Defines the Interface for a directed graph.- Version:
- (17/3/2021)
- Author:
- (SK)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addArc(T source, T destination)
Adds an arc to the graph, from source to destination.void
addVertex(T vertex)
Adds the input vertex to the graph.int
getNumArcs()
Returns the number of arcs in the graphint
getNumVertices()
Returns the number of vertices in the graphboolean
isArc(T vertex1, T vertex2)
Returns true iff a directed connection exists between the two input verticesboolean
isEmpty()
Returns true if the graph is empty and false otherwise.void
removeArc(T vertex1, T vertex2)
Removes the arc between v1 and v2.void
removeVertex(T vertex)
Removes the input vertex from the graph.void
saveToTGF(java.lang.String tgf_file_name)
Saves the current graph into a .tgf file.java.lang.String
toString()
Returns a string representation of the graph.
-
-
-
Method Detail
-
isEmpty
boolean isEmpty()
Returns true if the graph is empty and false otherwise.- Returns:
- boolean True iff the graph is empty
-
getNumVertices
int getNumVertices()
Returns the number of vertices in the graph- Returns:
- int The number of vertices in the graph
-
getNumArcs
int getNumArcs()
Returns the number of arcs in the graph- Returns:
- int The number of arcs in the graph
-
isArc
boolean isArc(T vertex1, T vertex2)
Returns true iff a directed connection exists between the two input vertices- Parameters:
T
- the first vertexT
- the second vertex- Returns:
- boolean true iff a directed connection exists from the first vertex to the second
-
addVertex
void addVertex(T vertex)
Adds the input vertex to the graph. If the vertex already exists in the graph, the graph is not changed.- Parameters:
T
- the vertex to be added to the graph
-
removeVertex
void removeVertex(T vertex)
Removes the input vertex from the graph. If the input vertex does not belong in the graph, the graph is not changed.- Parameters:
T
- The vertex to be removed.
-
addArc
void addArc(T source, T destination)
Adds an arc to the graph, from source to destination. If source or destination do not exist in the graph, the graph is not changed.- Parameters:
T
- the source of the arcT
- the destination of the arc
-
removeArc
void removeArc(T vertex1, T vertex2)
Removes the arc between v1 and v2. If v1 or v2, or the arc from v1 to v2 does not exist, the graph does not change.- Parameters:
T
- the source of the arc to be removedT
- the destination of the arc to be removed
-
toString
java.lang.String toString()
Returns a string representation of the graph.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String a string representation of this graph
-
saveToTGF
void saveToTGF(java.lang.String tgf_file_name)
Saves the current graph into a .tgf file.- Parameters:
the
- name of the file to write to
-
-