|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectGraph
ListOfEdgesGraph
This is a graph implementation that uses a linked-list of edges representation. The list of edges contains exactly one Edge object for every directed or undirected edge of the graph, if the graph is directed or undirected, respectively. Moreover, if the graph is undirected, the edges are stored such that in every Edge object, the source node is smaller than the target node. The list is not sorted; it contains the edges in reverse order of edge insertion, i.e., the node at the head of the list is the one that was added the most recently (and has not been removed, yet), and so on.
Field Summary |
Fields inherited from class Graph |
directed, nNodes |
Constructor Summary | |
ListOfEdgesGraph(int nodes,
boolean directed)
The class constructor. |
Method Summary | |
void |
addEdge(int source,
int target,
double weight)
This method adds an edge to the graph without checking whether the edge already exists. |
boolean |
addEdgeSafe(int source,
int target,
double weight)
This method adds an edge to the graph as follows: first check whether the edge already exists in the graph; if it does not exist, then add the edge and return true; if it does exist, then do nothing and return false. |
java.util.LinkedList |
getEdges()
|
void |
removeAllEdges()
This method removes all edges in the graph. |
double |
removeEdge(int source,
int target)
This method removes an edge as follows: if the graph contains an edge from source to target node, then this edge is removed and the weight of the edge is returned. |
Graph |
toAltGraphRepr(Graph g)
This method copies this graph to graph g, if g has the same number of nodes, and both g and this graph are directed, or both are undirected. |
java.lang.String |
toString()
|
double |
weightOfEdge(int source,
int target)
This method returns the weight of the edge from the source node to the target node, or +Infinity if no such edge exists. |
Methods inherited from class Graph |
addEdge, addEdgeSafe, getNNodes, isDirected |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ListOfEdgesGraph(int nodes, boolean directed)
nodes
- the number of nodes.directed
- true of the graph is directed.Method Detail |
public void addEdge(int source, int target, double weight)
Graph
addEdge
in class Graph
source
- the source of the edge to be added to the graph.target
- the target of the edge to be added to the graph.weight
- the weight of the edge to be added to the graph.public boolean addEdgeSafe(int source, int target, double weight)
Graph
addEdgeSafe
in class Graph
source
- the source of the edge to be added to the graph.target
- the target of the edge to be added to the graph.weight
- the weight of the edge to be added to the graph.
public double removeEdge(int source, int target)
Graph
removeEdge
in class Graph
source
- the source node of the edge to remove.target
- the target node of the edge to remove.
public void removeAllEdges()
Graph
removeAllEdges
in class Graph
public double weightOfEdge(int source, int target)
Graph
weightOfEdge
in class Graph
source
- the source node of the edge.target
- the target node of the edge.
public java.lang.String toString()
public Graph toAltGraphRepr(Graph g)
Graph
toAltGraphRepr
in class Graph
g
- the graph to copy this graph to.
public java.util.LinkedList getEdges()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |