diff options
| author | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-05 17:13:33 +0100 |
|---|---|---|
| committer | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-05 17:13:33 +0100 |
| commit | 152241c31e5861453f6b1b274924f0091d819fb0 (patch) | |
| tree | 86d1c89dd7cbd7b8dfd1ea8f9af4d02393e6b6c4 | |
| parent | ad7e8ed182a811c14263485f17a5bf996dd9f89c (diff) | |
| download | cycle-detector-152241c31e5861453f6b1b274924f0091d819fb0.tar.gz cycle-detector-152241c31e5861453f6b1b274924f0091d819fb0.zip | |
get each vertex's id and not just cast them to ints
| -rw-r--r-- | src/cycle_detection.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/cycle_detection.c b/src/cycle_detection.c index 8dd5691..6f6c9af 100644 --- a/src/cycle_detection.c +++ b/src/cycle_detection.c @@ -33,16 +33,16 @@ void cycle_detection(Graph *g) { // Compute in-degrees for (int i = 0; i < n; i++) { for (int j = 0; j < (int)g->vertices[i].out_neighbours->size; j++) { - int neighbor = *(int *)g->vertices[i].out_neighbours->data[j]; - indegree[neighbor]++; + Vertex neighbor = *(Vertex *) + g->vertices[i].out_neighbours->data[j]; + indegree[neighbor.id]++; } } // Add all vertices with no incoming edges for (int i = 0; i < n; i++) { - if (indegree[i] == 0) { + if (indegree[i] == 0) linked_list_append(queue, (void *)(intptr_t)i); - } } // Process queue for topological sort @@ -52,11 +52,11 @@ void cycle_detection(Graph *g) { // Process all neighbors of current vertex for (int j = 0; j < (int)g->vertices[top].out_neighbours->size; j++) { - int neighbor = *(int *)g->vertices[top].out_neighbours->data[j]; - indegree[neighbor]--; - if (!indegree[neighbor]) { - linked_list_append(queue, (void *)(intptr_t)neighbor); - } + Vertex neighbor = *(Vertex *) + g->vertices[top].out_neighbours->data[j]; + indegree[neighbor.id]--; + if (!indegree[neighbor.id]) + linked_list_append(queue, (void *)(intptr_t)neighbor.id); } } |