Function
void addEdge(const T& x, const T& y);
void addEdge(const T& x, const T& y, const double & w);
void addEdge(Edge<T> e);
Add a new edge into the graph to connected the node x and node y, with weight w. Default value of weight is 1.
Parameters
x, y, are label of the vertices to be connected by the new edge.
x and y must exist in the graph, otherwise the edge will not be add.
w is the weight of the edge. Default value of weight is 1.
Return value
None
Example
#include "HKUAL_graph.h"
#include <iostream>
using namespace std;
using namespace HKUAL;
int main(){
Graph<string> g;
g.addVertex("A");
g.addVertex("B");
g.addVertex("C");
g.addEdge("A", "B");
g.addEdge("A", "C", 2);
g.addEdge("B", "C", 10);
Edge<string> e("C","A");
g.addEdge(e);
return 0;
} |
Output
None
Time Complexity
, for is number of vertices in the graph.
|