|
Function
Vertex<T> parent(const T& x);
Get the parent of a specified vertex x, which is all vertices that vertex x directed to.
Parameters
x is the label of specified vertex.
Return value
Return a vector contain all parent vertices of x
Example
#include "HKUAL_graph.h"
#include <iostream>
#include <vector>
using namespace std;
using namespace HKUAL;
int main(){
DirectedGraph<string> g;
g.addVertex("A");
g.addVertex("B");
g.addVertex("C");
g.addEdge("A", "C");
g.addEdge("B", "C");
vector<Vertex<string> > v = g.parent("C");
for (int i = 0; i < v.size(); i++)
cout << v[i].label << endl;
return 0;
} |
Output
Time Complexity
, for is in degree of specified vertex and is total number of vertives
|