File: creation.c

package info (click to toggle)
igraph 0.10.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 16,176 kB
  • sloc: ansic: 121,500; cpp: 21,699; xml: 2,734; python: 411; makefile: 147; javascript: 20; sh: 9
file content (30 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <igraph.h>
#include <assert.h>

int main(void) {
    igraph_t graph;
    igraph_vector_int_t edges;

    /* Create a directed graph with no vertices or edges. */
    igraph_empty(&graph, 0, IGRAPH_DIRECTED);

    /* Add 5 vertices. Vertex IDs will range from 0 to 4, inclusive. */
    igraph_add_vertices(&graph, 5, NULL);

    /* Add 5 edges, specified as 5 consecutive pairs of vertex IDs
     * stored in an integer vector. */
    igraph_vector_int_init_int(&edges, 10,
                               0,1, 0,2, 3,1, 2,1, 0,4);
    igraph_add_edges(&graph, &edges, NULL);

    igraph_vector_int_destroy(&edges);

    /* Now the graph has 5 vertices and 5 edges. */
    assert(igraph_vcount(&graph) == 5);
    assert(igraph_ecount(&graph) == 5);

    igraph_destroy(&graph);

    return 0;
}