Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "intList.h"
- #include "loadgraph.h"
- #include "dfsTrace1.h"
- int white = 1, grey =2, black =3;
- int dfsSweep(IntList* nodeList, int* n, int* m, int* time, int* discoveryTime1, int* finishTime1, int* parent1, int* finishStk1){
- /*allocate colour array, init to white*/
- int *colour = calloc(*n+1,sizeof(int));
- int v;
- *time = 0;
- for (v=1; v<=*n; v++) {
- colour[v] = white;
- }
- /*for each vertex in v, check if white and call dfs*/
- for (v=1; v<=*n; v++) {
- if ((colour[v] = white)) {
- parent1[v] = -1;
- dfs(nodeList, colour, &v, time, n, m, discoveryTime1, finishTime1, parent1, finishStk1);
- }
- }
- //pg 345 - 347 dfstrace1
- //pg 362 dfsphase2
- /*debugging, args check*/
- printf("went into dfs\n");
- printf("n = %d\n",*n);
- printf("m = %d\n",*m);
- dfs(nodeList, n, m, discoveryTime1, finishTime1, parent1, finishStk1);
- printf("end of dfsSweep\n");
- return 0;
- }
- int dfs(IntList* nodeList, int* colour, int* v, int* time, int* n, int* m, int* discoveryTime1, int* finishTime1, int* parent1, int* finishStk1) {
- printf("begin dfs function\n");
- printf("time is %d\n",*time);
- int w;
- IntList remAdj;
- colour[*v] = grey;
- *time += 1;
- discoveryTime1[*v] = *time;
- printf("discoveryTime at v is %d\n",discoveryTime1[*v]);
- remAdj = nodeList[*v];
- while (remAdj != NULL) {
- w = intFirst(remAdj);
- if (colour[w] == white) {
- printf("end of one recursive call\n");
- parent1[w]=*v;
- dfs(nodeList, colour, &w, time, n, m, discoveryTime1, finishTime1, parent1, finishStk1);
- }
- remAdj = intRest(remAdj);
- }
- *time += 1;
- finishTime1[*v] = *time;
- printf("----time is: %d\n",*time);
- colour[*v] = black;
- printf("end of dfs\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement