diff options
| author | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-11 23:59:40 +0100 |
|---|---|---|
| committer | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-11 23:59:40 +0100 |
| commit | b392c57c4af46ec32d4797983d353a84c6846e98 (patch) | |
| tree | d75275272e84d3f27713abd829fea3c3889b121b /src/cycle_detection.c | |
| parent | 8cc886570da5c8ea0923741bdd2494eb34fb6989 (diff) | |
| download | cycle-detector-b392c57c4af46ec32d4797983d353a84c6846e98.tar.gz cycle-detector-b392c57c4af46ec32d4797983d353a84c6846e98.zip | |
Should just allocate this array on the stack
Diffstat (limited to '')
| -rw-r--r-- | src/cycle_detection.c | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/src/cycle_detection.c b/src/cycle_detection.c index 6f6c9af..4bbf62b 100644 --- a/src/cycle_detection.c +++ b/src/cycle_detection.c @@ -3,29 +3,21 @@ #include "linked_list.h" #include "vector.h" #include <stdio.h> -#include <stdlib.h> #include <stdint.h> void cycle_detection(Graph *g) { int n = g->num_vertices; - int *indegree = calloc(n, sizeof(int)); - if (!indegree) { - fprintf(stderr, "Memory allocation failed: could not create list.\n"); - free(indegree); - return; - } + int indegree[n]; LinkedList *queue = linked_list_new(); if (!queue) { fprintf(stderr, "Memory allocation failed: could not create queue.\n"); - free(indegree); return; } Vector *list = vector_new(); if (!list) { fprintf(stderr, "Memory allocation failed: could not create vector.\n"); - free(indegree); linked_list_delete(queue); return; } @@ -74,5 +66,4 @@ void cycle_detection(Graph *g) { linked_list_delete(queue); vector_delete(list); - free(indegree); } |