aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/graph.c24
-rw-r--r--src/graph.h8
2 files changed, 16 insertions, 16 deletions
diff --git a/src/graph.c b/src/graph.c
index 5f4b5d6..5ad439a 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -18,17 +18,17 @@ Graph *graph_new(int n) {
return NULL;
}
- graph->numEdges = n;
- graph->numVertices = 0;
+ graph->num_edges = n;
+ graph->num_vertices = 0;
for (int i = 0; i < n; i++) {
graph->vertices[i].id = i;
- graph->vertices[i].outNeighbours = linked_list_new();
- graph->vertices[i].inNeighbours = linked_list_new();
+ graph->vertices[i].out_neighbours = linked_list_new();
+ graph->vertices[i].in_neighbours = linked_list_new();
// if allocation for the linked lists failed
- if (!graph->vertices[i].outNeighbours
- || !graph->vertices[i].inNeighbours) {
+ if (!graph->vertices[i].out_neighbours
+ || !graph->vertices[i].in_neighbours) {
graph_delete(graph);
return NULL;
}
@@ -38,9 +38,9 @@ Graph *graph_new(int n) {
}
void graph_add_edge(Graph *g, int i, int j) {
- linked_list_append(g->vertices[i].outNeighbours, &g->vertices[j]);
- linked_list_append(g->vertices[j].inNeighbours, &g->vertices[i]);
- g->numEdges++;
+ linked_list_append(g->vertices[i].out_neighbours, &g->vertices[j]);
+ linked_list_append(g->vertices[j].in_neighbours, &g->vertices[i]);
+ g->num_edges++;
}
Graph *graph_read(const char *filename) {
@@ -72,9 +72,9 @@ Graph *graph_read(const char *filename) {
}
void graph_delete(Graph *g) {
- for (int i = 0; i < g->numVertices; i++) {
- linked_list_delete(g->vertices[i].inNeighbours);
- linked_list_delete(g->vertices[i].outNeighbours);
+ for (int i = 0; i < g->num_vertices; i++) {
+ linked_list_delete(g->vertices[i].in_neighbours);
+ linked_list_delete(g->vertices[i].out_neighbours);
}
free(g->vertices);
free(g);
diff --git a/src/graph.h b/src/graph.h
index ca90bbe..22b4ae5 100644
--- a/src/graph.h
+++ b/src/graph.h
@@ -7,13 +7,13 @@ 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
+ LinkedList *out_neighbours; // A linked list of vertices.
+ LinkedList *in_neighbours; // A linked list of vertices
};
struct Graph {
- int numVertices;
- int numEdges;
+ int num_vertices;
+ int num_edges;
Vertex *vertices; // An array of numVertices vertices
};