Package algs44

# Class EdgeWeightedDigraph

java.lang.Object
algs44.EdgeWeightedDigraph

public class EdgeWeightedDigraph extends Object
The `EdgeWeightedDigraph` class represents an directed graph of vertices named 0 through V-1, where each edge has a real-valued weight. It supports the following operations: add an edge to the graph, iterate over all of edges leaving a vertex. Parallel edges and self-loops are permitted.

For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

• ## Field Summary

Fields
Modifier and Type
Field
Description
`private final Bag<DirectedEdge>[]`
`adj`

`private int`
`E`

`private final int`
`V`

• ## Constructor Summary

Constructors
Constructor
Description
`EdgeWeightedDigraph(int V)`
Create an empty edge-weighted digraph with V vertices.
```EdgeWeightedDigraph(int V, int E)```
Create a random edge-weighted graph with V vertices and E edges with no parallel edges or self loops.
```EdgeWeightedDigraph(int V, int E, boolean allowParallelEdgesAndSelfLoops)```
Create a random edge-weighted graph with V vertices and E edges.
`EdgeWeightedDigraph(EdgeWeightedDigraph G)`
Copy constructor.
`EdgeWeightedDigraph(In in)`
Create an edge-weighted digraph from input stream.
• ## Method Summary

Modifier and Type
Method
Description
`void`
`addEdge(DirectedEdge e)`
Add the edge e to this digraph.
`Iterable<DirectedEdge>`
`adj(int v)`
Return the edges leaving vertex v as an Iterable.
`int`
`E()`
Return the number of edges in this digraph.
`Iterable<DirectedEdge>`
`edges()`
Return all edges in this graph as an Iterable.
`static void`
`main(String[] args)`
Test client.
`int`
`outdegree(int v)`
Return number of edges leaving v.
`void`
`toGraphviz(String filename)`
Save a graphviz representation of the graph.
`String`
`toString()`
Return a string representation of this graph.
`int`
`V()`
Return the number of vertices in this digraph.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ## Field Details

• ### V

private final int V
• ### E

private int E

• ## Constructor Details

• ### EdgeWeightedDigraph

public EdgeWeightedDigraph(int V)
Create an empty edge-weighted digraph with V vertices.
• ### EdgeWeightedDigraph

public EdgeWeightedDigraph(int V, int E)
Create a random edge-weighted graph with V vertices and E edges with no parallel edges or self loops. The expected running time is proportional to V + E.
• ### EdgeWeightedDigraph

public EdgeWeightedDigraph(int V, int E, boolean allowParallelEdgesAndSelfLoops)
Create a random edge-weighted graph with V vertices and E edges. The expected running time is proportional to V + E.
• ### EdgeWeightedDigraph

public EdgeWeightedDigraph(In in)
Create an edge-weighted digraph from input stream.
• ### EdgeWeightedDigraph

Copy constructor.
• ## Method Details

• ### V

public int V()
Return the number of vertices in this digraph.
• ### E

public int E()
Return the number of edges in this digraph.

Add the edge e to this digraph.

Return the edges leaving vertex v as an Iterable. To iterate over the edges leaving vertex v, use foreach notation: `for (DirectedEdge e : graph.adj(v))`.
• ### edges

public  edges()
Return all edges in this graph as an Iterable. To iterate over the edges, use foreach notation: `for (DirectedEdge e : graph.edges())`.
• ### outdegree

public int outdegree(int v)
Return number of edges leaving v.
• ### toString

public String toString()
Return a string representation of this graph.
Overrides:
`toString` in class `Object`
• ### toGraphviz

public void toGraphviz(String filename)
Save a graphviz representation of the graph. See graphviz.org.
• ### main

public static void main(String[] args)
Test client.