DirectedGraph::eulerianPath

Function


vector<DirectedEdge<T> > eulerianPath();

Returns the edges that use to form the eulerian path by the order of path go through.

Parameters

None

Return value

Return the vector of by the order of path go through.

Example

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

int main(){
    int n;
    DirectedGraph<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("D","A");
    vector<DirectedEdge<string> > v = g.eulerianPath();
    for (int i = 0; i < v.size(); i++)
	     cout << v[i].X << ' ' << v[i].Y << endl;
    return 0;
}

Output

A B
B C
C D
D A
A C

Time Complexity

, for is number of edges and is total number of vertices.

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