fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct vertex
  5. {
  6. char color ;
  7. int d ;
  8. };
  9. int size;
  10.  
  11. void push(int v[],int *f ,int *r,int d)
  12. {
  13. if(*r == size )
  14. {
  15. printf("The Queue is full\n");
  16. }
  17. else if(*f == -1)
  18. {
  19. *f =1;
  20. *r = 1;
  21. v[*r] = d;
  22. }
  23. else
  24. {
  25. *r = *r++;
  26. v[*f] = d;
  27. }
  28. }
  29.  
  30. int pop(int v[], int *f,int *r)
  31. {
  32. int x;
  33. if(*f == -1)
  34. {
  35. return -1;
  36. }
  37. else
  38. {
  39. x = v[*f];
  40. *f++;
  41. return x ;
  42. }
  43. }
  44.  
  45. void BFS(int ar[size+1][size+1])
  46. {
  47. int i;
  48. struct vertex v[size+1];
  49. for(i=1;i<=size;i++)
  50. {
  51. v[i].color = 'w';
  52. v[i].d = 0;
  53. }
  54. int visted[size+1];
  55. int x;
  56. int front=-1,rear=-1;
  57. v[1].color = 'g';
  58. v[1].d = 0;
  59. push(visted,&front,&rear,1);
  60. while(front != -1 && front < rear)
  61. {
  62. int x = pop(visted,&front,&rear);
  63. printf("%d \t",x);
  64. for(i =1;i<=size;i++)
  65. {
  66. if(ar[x][i]==1 && v[i].color=='w')
  67. {
  68. v[i].color = 'g';
  69. v[i].d = v[x].d + 1;
  70. }
  71. push(visted,&front,&rear,i);
  72. }
  73. v[x].color = 'b';
  74. }
  75. }
  76.  
  77. int main()
  78. {
  79. int a,b,i,j;
  80. printf("Enter Number of vertex : ");
  81. scanf("%d \n",&size);
  82. int ar[size+1][size+1];
  83. for(i=1;i<=size;i++)
  84. {
  85. for(j=1;j<=size;j++)
  86. {
  87. ar[i][j]=0;
  88. }
  89. }
  90. for(i =1;i<=size;i++)
  91. {
  92. printf( "Enter No. of vetex that are adjecent to %d :",i);
  93. scanf("%d \n",&a);
  94. printf("Enter the vertices\n");
  95. for(j = 1;j<=a;j++)
  96. {
  97. scanf("%d",&b);
  98. ar[j][b] = 1;
  99. }
  100. }
  101. printf("The BSF Result is:\n");
  102. BSF(ar);
  103.  
  104. return 0;
  105. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘push’:
prog.c:25:10: warning: operation on ‘r’ may be undefined [-Wsequence-point]
   *r = *r++;
         ~^~
prog.c: In function ‘pop’:
prog.c:40:3: warning: value computed is not used [-Wunused-value]
   *f++;
   ^~~~
prog.c: In function ‘BFS’:
prog.c:55:6: warning: unused variable ‘x’ [-Wunused-variable]
  int x;
      ^
prog.c: In function ‘main’:
prog.c:102:2: warning: implicit declaration of function ‘BSF’ [-Wimplicit-function-declaration]
  BSF(ar);
  ^~~
/home/zvUfZY/ccGpU1j2.o: In function `main':
prog.c:(.text.startup+0x14d): undefined reference to `BSF'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty