Graph::size

Function


int size ( );

Returns the number of vertices in the graph.

Parameters

None

Return value

The number of vertices in the graph.

Example

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

int main(){
    Graph<string> g;
    g.addVertex("A");
    g.addVertex("B");
    Graph<string> g2;
    
    cout << g.size() << endl;
    cout << g2.size() << endl;
    return 0;
}

Output

2
0

Time Complexity

, for is number of vertices.

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