public abstract class Graph extends java.lang.Object implements GraphInterface
Constructor and Description |
---|
Graph() |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(Edge e)
Adds to the graph a new edge
|
void |
addEdge(int u,
int v)
Adds to the graph a new edge
|
abstract void |
addEdge(int u,
int v,
int weight)
Adds to the graph a new edge
|
abstract GraphInterface |
create()
Creates a new object of the same class as this, with the same number of nodes and no edges
|
abstract GraphInterface |
create(int order)
Creates a new object of the same class as this, with order nodes and no edges
|
int |
getEdgeNum()
The number of edges of this graph
|
java.lang.Iterable<java.lang.Integer> |
getNeighbors(int u)
Returns the neighbors of node u, as an iterable
|
int |
getOrder()
The number of nodes of this graph
|
java.lang.Iterable<Edge> |
getOutEdges(int u)
Returns the edges incident to node u, as an iterable
|
boolean |
hasEdge(Edge e)
Whether this graph has the specified edge
|
boolean |
hasEdge(int u,
int v)
Whether this graph has the specified edge
|
abstract void |
removeEdge(int u,
int v)
Removes the specified edge from the graph (if the egde exists)
|
abstract java.lang.String |
serialize()
A String representation of the graph in the format:
"\n" separated lines; first line = number of nodes;
each subsequent line is an edge in the format: head tail weight
|
java.lang.String |
toString() |
public abstract GraphInterface create()
GraphInterface
create
in interface GraphInterface
public abstract GraphInterface create(int order)
GraphInterface
create
in interface GraphInterface
order
- the number of nodespublic void addEdge(int u, int v)
GraphInterface
addEdge
in interface GraphInterface
u
- tail of the new edgev
- head of the new edgepublic abstract void addEdge(int u, int v, int weight)
GraphInterface
addEdge
in interface GraphInterface
u
- tail of the new edgev
- head of the new edgeweight
- weight of the new edgepublic void addEdge(Edge e)
GraphInterface
addEdge
in interface GraphInterface
e
- the new edge that is to be addedpublic boolean hasEdge(int u, int v)
GraphInterface
hasEdge
in interface GraphInterface
u
- of the sought edgev
- of the sought edgepublic boolean hasEdge(Edge e)
GraphInterface
hasEdge
in interface GraphInterface
e
- the edgepublic int getOrder()
GraphInterface
getOrder
in interface GraphInterface
public int getEdgeNum()
GraphInterface
getEdgeNum
in interface GraphInterface
public abstract void removeEdge(int u, int v)
GraphInterface
removeEdge
in interface GraphInterface
u
- tail of the edge to be removedv
- head of the edge to be removedpublic java.lang.Iterable<java.lang.Integer> getNeighbors(int u)
GraphInterface
getNeighbors
in interface GraphInterface
u
- the node whose neighbors are requiredpublic java.lang.Iterable<Edge> getOutEdges(int u)
GraphInterface
getOutEdges
in interface GraphInterface
u
- the node whose incident edges are requiredpublic abstract java.lang.String serialize()
GraphInterface
serialize
in interface GraphInterface
public java.lang.String toString()
toString
in class java.lang.Object