class Edge
Each object of this class represents a single directed edge (or arc) in a graph. The edge object itself stores some useful data fields that can be used in various graph algorithms. In particular, an edge stores its cost, which is important for weighted graphs.
Previous versions of this class in the library included member variables such as visited
to help facilitate the implementation of various graph algorithms.
These were removed by the library's maintainer because we want our students to learn to manage such data themselves using collections.
See also:
BasicGraph
,
Vertex
Available since: 2014/02/01 version of C++ library
Constructor | |
Edge(start, end, cost) | Creates a edge between the given vertices. |
Methods | |
Deprecated. Sets the visited field back to its initial value. This will be removed from the library; students should not use it. | |
Returns a string representation of this edge. | |
Fields | |
The cost or weight of this edge. | |
A pointer to the finishing vertex touching this edge (alias for finish ). | |
A pointer to the finishing vertex touching this edge. | |
A pointer to the starting vertex touching this edge. | |
Deprecated. Whether or not this edge has currently been visited; initially false . This will be removed from the library; students should not use it. | |
The cost or weight of this edge (alias for cost ). |
Edge(Vertex* start, Vertex* finish, double cost = 0);
Usage:
Edge e1(v1, v2); Edge e2(v2, v3, 4.5);
void resetData();
visited
field back to its initial value of false
.
Usage:
e.resetData();
string toString() const;
"Edge{start=r12c42, finish=r12c41, cost=0.75}"
.
Usage:
string str = e.toString();