Graph::neighbour

Function


vector<Vertex<T> > neighbour(const T& x);

Get the neighbour of a specified vertex.

Parameter

x is label of specified vertex.

Return value

Return a vector contain all neigbour vertices of x.

Example

#include "HKUAL_graph.h"
#include <iostream>
#include <vector>
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");
    vector<Vertex<string> > v = g.neighbour("A");
    for (int i = 0; i < v.size(); i++)
        cout << v[i].label << endl;
    return 0;
}

Output

B
C

Time Complexity

, for is degree of specified vertex and is total number of vertives.

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