DirectedGraph::addVertex

Function


void addVertex ( const T& x );
void addVertex ( Vertex <T> v);

Add a new vertex into the directed graph. The label of the new vertex will be a local copy of x.

Parameters

x, is label of the new vertex. If the vertex with same label exists in the graph, the new vertex will not be added into the graph.

Return value

None

Example

#include "HKUAL_graph.h"
#include <iostream>
using namespace std;
using namespace HKUAL;

int main(){
    DirectedGraph<string> g;
    g.addVertex("A");
    g.addVertex("B");
    Vertex<string> v("C");
    g.addVertex(v);
    return 0;
}

Output

None

Time Complexity

, for is number of vertices in the graph.

© The University of Hong Kong Algorithms Library - hkual@cs.hku.hk