#include "basicgraph.h"

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(startfinish)
Edge(startendcost) 
Creates a edge between the given vertices.
Methods
resetData()Deprecated. Sets the visited field back to its initial value. This will be removed from the library; students should not use it.
toString()Returns a string representation of this edge.
Fields
double costThe cost or weight of this edge.
Vertex*& endA pointer to the finishing vertex touching this edge (alias for finish).
Vertex* finishA pointer to the finishing vertex touching this edge.
Vertex* startA pointer to the starting vertex touching this edge.
bool visitedDeprecated. Whether or not this edge has currently been visited; initially false. This will be removed from the library; students should not use it.
double& weightThe cost or weight of this edge (alias for cost).

Constructor detail


Edge(Vertex* start, Vertex* finish, double cost = 0);
Creates a edge between the given vertices. A cost may be optionally passed to indicate a weighted edge; if no cost is passed, 0 is used.

Usage:

Edge e1(v1, v2);
Edge e2(v2, v3, 4.5);

Method detail


void resetData();
Deprecated. Sets the visited field back to its initial value of false.

Usage:

e.resetData();

string toString() const;
Returns a string representation of this edge, such as "Edge{start=r12c42, finish=r12c41, cost=0.75}".

Usage:

string str = e.toString();