Skip to main content

Creating Your First Graph

  1. In your main.cpp import Graaf:
#include <graaflib/graph.h>
  1. Define a directed graph g
graaf::directed_graph<const char, int> g;
  1. Add vertices to the graph:
const auto a = g.add_vertex('a');
const auto b = g.add_vertex('b');
const auto c = g.add_vertex('c');
  1. Connect the vertices with edges:
g.add_edge(a, b, 1);
g.add_edge(a, c, 1);
  1. Putting it all together:
#include <graaflib/graph.h>

int main()
{
graaf::directed_graph<const char, int> g;

const auto a = g.add_vertex('a');
const auto b = g.add_vertex('b');
const auto c = g.add_vertex('c');

g.add_edge(a, b, 1);
g.add_edge(a, c, 1);

return 0;
}

Congratulations! You just created the following graph 🎉​

Directed graph example