aboutsummaryrefslogtreecommitdiff
path: root/src/graph.h
blob: ca90bbee54471a6465a5450aeb4e6f98b3205193 (plain)
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
31
32
33
34
35
36
37
38
39
40
#ifndef GRAPH_H
#define GRAPH_H

#include "linked_list.h"

typedef struct Vertex Vertex;
typedef struct Graph Graph;
struct Vertex {
    int id; // a number in [0; numVertices[
    LinkedList *outNeighbours; // A linked list of vertices.
    LinkedList *inNeighbours; // A linked list of vertices
};

struct Graph {
    int numVertices;
    int numEdges;
    Vertex *vertices; // An array of numVertices vertices
};

// Allocates and constructs a new graph with n vertices.
// Returns a pointer to the new graph, or NULL on error.
// Post: the caller owns the graph.
Graph *graph_new(int n);

// Adds an edge from the i'th to the j'th vertex (0-indexed).
void graph_add_edge(Graph *g, int i, int j);

// Reads a graph from the given file and returns a newly
// constructed Graph representing it.
// Returns a pointer to the read graph, or NULL on error.
// Post: the caller owns the graph.
Graph *graph_read(const char *filename);

// Deallocates the given graph and all its associated memory.
void graph_delete(Graph *g);

// Prints some useful information about the given graph.
void graph_print(Graph *g);

#endif // GRAPH_H