aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Thestrup <mithe24@student.sdu.dk>2025-12-11 23:59:40 +0100
committerMikkel Thestrup <mithe24@student.sdu.dk>2025-12-11 23:59:40 +0100
commitb392c57c4af46ec32d4797983d353a84c6846e98 (patch)
treed75275272e84d3f27713abd829fea3c3889b121b
parent8cc886570da5c8ea0923741bdd2494eb34fb6989 (diff)
downloadcycle-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.c11
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);
}