-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectCycle.c
More file actions
executable file
·44 lines (36 loc) · 1001 Bytes
/
detectCycle.c
File metadata and controls
executable file
·44 lines (36 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "fileParser.h"
#include "graphNode.h"
#include "constants.h"
int detectCycle(targetNode *headTarget)
{
targetList *currDependentTarget;
//Base Case: If there are no children, return 0;
if(headTarget->dependentTargets->nextTarget == NULL)
{
//No cycle at this point
return 0;
}
else
{
//Recursive Case: Check all children for cycles
if(headTarget->hasVisited)
{
fprintf(stderr, "Cycle Detected\n");
exit(EXIT_FAILURE);
}
else
{
headTarget->hasVisited = 1;
currDependentTarget = headTarget->dependentTargets->nextTarget;
while(currDependentTarget != NULL)
{
detectCycle(currDependentTarget->target);
currDependentTarget = currDependentTarget->nextTarget;
}
}
}
return 0;
}