aboutsummaryrefslogtreecommitdiff
path: root/src/graph.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graph.c')
-rw-r--r--src/graph.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/graph.c b/src/graph.c
index 0a15f40..44ce400 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -1,5 +1,5 @@
#include "graph.h"
-#include "linked_list.h"
+#include "vector.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -23,8 +23,8 @@ Graph *graph_new(int n) {
for (int i = 0; i < n; i++) {
graph->vertices[i].id = i;
- graph->vertices[i].out_neighbours = linked_list_new();
- graph->vertices[i].in_neighbours = linked_list_new();
+ graph->vertices[i].out_neighbours = vector_new();
+ graph->vertices[i].in_neighbours = vector_new();
// if allocation for the linked lists failed
if (!graph->vertices[i].out_neighbours
@@ -38,23 +38,11 @@ Graph *graph_new(int n) {
}
void graph_add_edge(Graph *g, int i, int j) {
- linked_list_append(g->vertices[i].out_neighbours, &g->vertices[j]);
- linked_list_append(g->vertices[j].in_neighbours, &g->vertices[i]);
+ vector_push(g->vertices[i].out_neighbours, &g->vertices[j]);
+ vector_push(g->vertices[j].in_neighbours, &g->vertices[i]);
g->num_edges++;
}
-void graph_remove_edge(Graph *g, int i, int j) {
- LinkedListNode *in_node = linked_list_find(
- g->vertices[i].out_neighbours,
- &g->vertices[j]);
- LinkedListNode *out_node = linked_list_find(
- g->vertices[j].in_neighbours,
- &g->vertices[j]);
- linked_list_remove(g->vertices[i].out_neighbours, in_node);
- linked_list_remove(g->vertices[j].in_neighbours, out_node);
- g->num_edges--;
-}
-
Graph *graph_read(const char *filename) {
FILE *file = fopen(filename, "r");
if (!file)
@@ -110,8 +98,8 @@ void graph_print(Graph *g) {
void graph_delete(Graph *g) {
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);
+ vector_delete(g->vertices[i].in_neighbours);
+ vector_delete(g->vertices[i].out_neighbours);
}
free(g->vertices);
free(g);