Advertisement
Guest User

Untitled

a guest
May 28th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "intList.h"
  5. #include "loadgraph.h"
  6. #include "dfsTrace1.h"
  7. int white = 1, grey =2, black =3;
  8.  
  9. int dfsSweep(IntList* nodeList, int* n, int* m, int* time, int* discoveryTime1, int* finishTime1, int* parent1, int* finishStk1){
  10. /*allocate colour array, init to white*/
  11. int *colour = calloc(*n+1,sizeof(int));
  12. int v;
  13. *time = 0;
  14.  
  15. for (v=1; v<=*n; v++) {
  16. colour[v] = white;
  17. }
  18.  
  19. /*for each vertex in v, check if white and call dfs*/
  20. for (v=1; v<=*n; v++) {
  21. if ((colour[v] = white)) {
  22. parent1[v] = -1;
  23. dfs(nodeList, colour, &v, time, n, m, discoveryTime1, finishTime1, parent1, finishStk1);
  24. }
  25. }
  26.  
  27. //pg 345 - 347 dfstrace1
  28. //pg 362 dfsphase2
  29.  
  30. /*debugging, args check*/
  31. printf("went into dfs\n");
  32. printf("n = %d\n",*n);
  33. printf("m = %d\n",*m);
  34. dfs(nodeList, n, m, discoveryTime1, finishTime1, parent1, finishStk1);
  35.  
  36.  
  37. printf("end of dfsSweep\n");
  38. return 0;
  39. }
  40.  
  41. int dfs(IntList* nodeList, int* colour, int* v, int* time, int* n, int* m, int* discoveryTime1, int* finishTime1, int* parent1, int* finishStk1) {
  42. printf("time is %d\n",*time);
  43. discoveryTime1[*v] = *time;
  44.  
  45.  
  46. int w;
  47. IntList remAdj;
  48. printf("repeat dfs function\n");
  49. colour[*v] = grey;
  50. *time += 1;
  51.  
  52. printf("discoveryTime at v is %d\n",discoveryTime1[*v]);
  53.  
  54. remAdj = nodeList[*v];
  55. while (remAdj != NULL) {
  56. w = intFirst(remAdj);
  57. if (colour[w] == white) {
  58. printf("end of one recursive call\n");
  59. dfs(nodeList, colour, &w, time, n, m, discoveryTime1, finishTime1, parent1, finishStk1);
  60. }
  61. remAdj = intRest(remAdj);
  62. }
  63.  
  64. *time += 1;
  65. finishTime1[*v] = *time;
  66. printf("----time is: %d\n",*time);
  67. colour[*v] = black;
  68.  
  69. printf("end of dfs\n");
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement