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
Time Complexity
, for is degree of specified vertex and is total number of vertives.
|