#include "BaseGraph/undirected_graph.hpp"

Undirected graph (unlabeled)

UndirectedGraph class is a special case of LabeledUndirectedGraph that has no edge labels. They share most of their methods.

Usage

To create a UndirectedGraph of 5 vertices, use

BaseGraph::UndirectedGraph graph(5);

The vertices of this graph are labeled 0, 1, 2, 3, 4. To add an edge, we use the method addEdge

graph.addEdge(0, 1);
graph.addEdge(3, 2);

If we try to make an operation on a vertex outside the graph range, an std::out_of_range exception is thrown

// graph.addEdge(1, 5); throws std::out_of_range

Here is a small example that computes the degree of a vertex

 1#include "BaseGraph/undirected_graph.hpp"
 2
 3#include <iostream>
 4
 5int main() {
 6    BaseGraph::UndirectedGraph graph(10);
 7    graph.addEdge(0, 1);
 8    graph.addEdge(2, 3);
 9    graph.addEdge(2, 4);
10    graph.addEdge(3, 4);
11
12    std::cout << graph << std::endl;
13    std::cout << "The degree of vertex 2 is: " << graph.getDegree(2)
14              << std::endl;
15    return 0;
16}

Detailed documentation

See LabeledUndirectedGraph.

using BaseGraph::UndirectedGraph = LabeledUndirectedGraph<NoLabel>

Unlabeled undirected graph.