36 Node(
const T& value) : data(value), next(
nullptr) {}
50 Vertex* findVertex(
const T& value)
52 Vertex* current = vertices;
55 if (current->data == value)
57 current = current->next;
70 Vertex* temp = vertices;
71 while (temp->adjacencyList)
73 Node* adjTemp = temp->adjacencyList;
74 temp->adjacencyList = temp->adjacencyList->next;
77 vertices = vertices->next;
85 if (!findVertex(value))
87 Vertex* newVertex =
new Vertex{value,
nullptr, vertices};
95 Vertex* fromVertex = findVertex(from);
96 Vertex* toVertex = findVertex(to);
98 if (!fromVertex || !toVertex)
101 Node* newEdge =
new Node(to);
102 newEdge->next = fromVertex->adjacencyList;
103 fromVertex->adjacencyList = newEdge;
void addVertex(const T &value)
Adds value as a vertex if it isn't already present.
void addEdge(const T &from, const T &to)
Adds a directed edge from -> to; no-ops if either vertex is missing.
~Graph()
Frees every vertex and its adjacency list.
Root namespace for everything the engine exposes.