From a846e5e8b6442f6aa9ad738e2173da3211325f8e Mon Sep 17 00:00:00 2001 From: Mikkel Thestrup Date: Wed, 3 Dec 2025 22:38:44 +0100 Subject: Added graph_remove_edge() --- src/graph.c | 12 ++++++++++++ src/graph.h | 1 + 2 files changed, 13 insertions(+) (limited to 'src') diff --git a/src/graph.c b/src/graph.c index 5ad439a..f3e7517 100644 --- a/src/graph.c +++ b/src/graph.c @@ -43,6 +43,18 @@ void graph_add_edge(Graph *g, int i, int j) { 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"); char line[1024]; diff --git a/src/graph.h b/src/graph.h index 22b4ae5..54d4f7a 100644 --- a/src/graph.h +++ b/src/graph.h @@ -30,6 +30,7 @@ void graph_add_edge(Graph *g, int i, int j); // Returns a pointer to the read graph, or NULL on error. // Post: the caller owns the graph. Graph *graph_read(const char *filename); +void graph_remove_edge(Graph *g, int i, int j); // Deallocates the given graph and all its associated memory. void graph_delete(Graph *g); -- cgit v1.2.3-70-g09d2