fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n;
  4. cout<<"enter the number of vertics";
  5. cin>>n;
  6.  
  7. int arr[n][n];
  8. int visit[n];
  9. int front=0;
  10. int rear=0;
  11. int queue[100]={-1};
  12. void enqueue(int data)
  13. {
  14. rear=(rear+1)%100;
  15. queue[rear]=data;
  16. }
  17. int dequeue()
  18. {
  19. front++;
  20. return queue[front-1];
  21. }
  22. void BFS(int index)
  23. {
  24. int j;
  25. visit[index]=1;
  26. enqueue(index);
  27.  
  28. while(front<rear)
  29. {
  30. index=dequeue();
  31. visit[index]=1;
  32. cout<<index<<' ';
  33. for(j=0;j<n;j++)
  34. {
  35. if(visit[j]!=1)
  36. enqueue(arr[index][j]);
  37. }
  38. }
  39. }
  40. int main()
  41. {
  42. int i,j;
  43.  
  44. cout<<"now enter the matrix";
  45. for(i=0;i<n;i++)
  46. for(j=0;j<n;j++)
  47. {
  48. cin>>arr[i][j];
  49. }
  50.  
  51. BFS(0);
  52. return 0;
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4
0 1 1 0
1 0 0 0
1 0 0 0
0 0 1 0
compilation info
prog.cpp:4:1: error: ‘cout’ does not name a type
 cout<<"enter the number of vertics";
 ^~~~
prog.cpp:5:1: error: ‘cin’ does not name a type
 cin>>n;
 ^~~
prog.cpp:7:10: error: array bound is not an integer constant before ‘]’ token
 int arr[n][n];
          ^
prog.cpp:7:13: error: array bound is not an integer constant before ‘]’ token
 int arr[n][n];
             ^
prog.cpp:8:12: error: array bound is not an integer constant before ‘]’ token
 int visit[n];
            ^
prog.cpp: In function ‘void enqueue(int)’:
prog.cpp:15:2: error: reference to ‘queue’ is ambiguous
  queue[rear]=data;
  ^~~~~
prog.cpp:11:5: note: candidates are: int queue [100]
 int queue[100]={-1};
     ^~~~~
In file included from /usr/include/c++/6/queue:64:0,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:86,
                 from prog.cpp:1:
/usr/include/c++/6/bits/stl_queue.h:96:11: note:                 template<class _Tp, class _Sequence> class std::queue
     class queue
           ^~~~~
prog.cpp: In function ‘int dequeue()’:
prog.cpp:20:9: error: reference to ‘queue’ is ambiguous
  return queue[front-1];
         ^~~~~
prog.cpp:11:5: note: candidates are: int queue [100]
 int queue[100]={-1};
     ^~~~~
In file included from /usr/include/c++/6/queue:64:0,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:86,
                 from prog.cpp:1:
/usr/include/c++/6/bits/stl_queue.h:96:11: note:                 template<class _Tp, class _Sequence> class std::queue
     class queue
           ^~~~~
prog.cpp: In function ‘void BFS(int)’:
prog.cpp:25:2: error: ‘visit’ was not declared in this scope
  visit[index]=1;
  ^~~~~
prog.cpp:36:12: error: ‘arr’ was not declared in this scope
    enqueue(arr[index][j]);
            ^~~
prog.cpp: In function ‘int main()’:
prog.cpp:48:8: error: ‘arr’ was not declared in this scope
   cin>>arr[i][j];
        ^~~
stdout
Standard output is empty