Advertisement
Guest User

Untitled

a guest
May 28th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 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("begin dfs function\n");
  43. printf("time is %d\n",*time);
  44. int w;
  45. IntList remAdj;
  46. colour[*v] = grey;
  47. *time += 1;
  48. discoveryTime1[*v] = *time;
  49. printf("discoveryTime at v is %d\n",discoveryTime1[*v]);
  50.  
  51. remAdj = nodeList[*v];
  52. while (remAdj != NULL) {
  53. w = intFirst(remAdj);
  54. if (colour[w] == white) {
  55. printf("end of one recursive call\n");
  56. parent1[w]=*v;
  57. dfs(nodeList, colour, &w, time, n, m, discoveryTime1, finishTime1, parent1, finishStk1);
  58. }
  59. remAdj = intRest(remAdj);
  60. }
  61.  
  62. *time += 1;
  63. finishTime1[*v] = *time;
  64. printf("----time is: %d\n",*time);
  65. colour[*v] = black;
  66.  
  67. printf("end of dfs\n");
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement