Graph::getEdges

Function


vector<Edge<T> >getEdges();

Returns all edges in the graph.

Parameters

None

Return value

Return the vector contain all edges in the graph.

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.addVertex("D");
	
    g.addEdge("A","B");
    g.addEdge("A","C");
    g.addEdge("B","C");
    g.addEdge("C","D");
    g.addEdge("A","D");
    vector<Edge<string> > v = g.getEdges();
    for (int i = 0; i < v.size(); i++)
        cout << v[i].X << ' ' << v[i].Y << endl;
    return 0;
}

Output

A B
A C
B C
C D
A D

Time Complexity

, for is total number of edges.

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