#include "basicgraph.h"

class Vertex

Each object of this class represents a single vertex (or node) in a graph. Previous versions of this class in the library included member variables such as visited and previous 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, Edge

Available since: 2014/02/01 version of C++ library

Constructor
Vertex(name) Creates a vertex with the given name.
Methods
getColor()Returns the color of this vertex.
resetData()Sets the vertex's color back to its initial value.
setColor(color)Sets this vertex's color to the given color.
toString()Returns a string representation of this vertex.
Fields
Set<Edge*> arcsDeprecated. A set of pointers to all outbound arcs (edges) from this vertex. We suggest you refer to this field as edges rather than arcs, though either will work.
double costDeprecated. The cost to reach this vertex; initially 0. This will be removed from the library; students should not use it.
Set<Edge*>& edgesA set of pointers to all outbound edges from this vertex. (An alias for arcs.)
string nameThe name of this vertex in the graph.
Vertex* previousDeprecated. A pointer to a previous vertex; initially nullptr. This will be removed from the library; students should not use it.
bool visitedDeprecated. Whether or not this vertex has currently been visited; initially false. This will be removed from the library; students should not use it.
double& weightDeprecated. The cost to reach this vertex (an alias for cost). This will be removed from the library; students should not use it.

Constructor detail


Vertex(string name);
Creates a vertex with the given name. Generally clients should not directly construct Vertex objects but should instead add vertexes by name to a BasicGraph which will then internally create the Vertex structure for you.

Usage:

Vertex* vp = new Vertex(name);

Method detail


int getColor();
Returns the color of the given vertex, as set previously by a call to setColor. If setColor has not been called previously, the return value is unspecified.

Usage:

int color = vp->getColor();

void resetData();
Sets the vertex's color back to its initial value.

Usage:

vp->resetData();

void setColor(int color);
Sets the color of the given vertex to the given color. Future calls to getColor will return this color.

Usage:

vp->setColor(color);

string toString() const;
Returns a string representation of this vertex, such as "Vertex{name=r13c42, neighbors={r12c41, r12c43}}".

Usage:

string str = vp->toString();