Thread: Problem with breat first Search

  1. #1
    Registered User
    Join Date
    Nov 2011
    Location
    Buea, Cameroon
    Posts
    197

    Problem with breat first Search

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    #define N 100000
    
    int A[N][2];
    
    void bfs()
    {
      for(i=1 ;i <=n; i++)
       if(a[v][i] && !visited[i])
        q[++r]=i;
      if(f<=r)
      {
       visited[q[f]]=1;
       bfs(q[f++]);
      }
    }
    
    int main(void) {
    
    	int n = 0, ans = 0;
    	int a, i;
    
    	for(a = 0; a < 21; a++) {
    
      scanf(" %d", &n);
      printf(" N: %d", n);
    
      if( n == -1) {
       goto end;
      }
    
      for( i = 1; i < n + 1; i++){
       scanf(" %d", &A[i][0]);
      }
      printf(" leaves for looop.....\n\n");
    
      //det num rides. BFS
      for( i = 1; i < n + 1; i++) {
       //enters for...
       printf("\n Empty for...");
       ans++;
    
          BFS(A[i])
       int k = 0;
       int j = A[i][0];
    
       
       printf("\nEnd while....");
       printf("\nans: %d", ans);
      next: ;
       for(k = 1; k < n+1; k++)
        A[i][1] = 0;
      }
      printf("\nEnd problem....");
    	
      end: ;
      printf(" %d", ans);
    	}
    
    	return 0;
    }

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Nyah Check View Post
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdbool.h>
    
    
    #define N 100000
    
    int A[N][2];
    
    void bfs()
    {
      for(i=1 ;i <=n; i++)
       if(a[v][i] && !visited[i])
        q[++r]=i;
      if(f<=r)
      {
       visited[q[f]]=1;
       bfs(q[f++]);
      }
    }
    
    int main(void) {
    
        int n = 0, ans = 0;
        int a, i;
    
        for(a = 0; a < 21; a++) {
    
      scanf(" %d", &n);
      printf(" N: %d", n);
    
      if( n == -1) {
       goto end;
      }
    
      for( i = 1; i < n + 1; i++){
       scanf(" %d", &A[i][0]);
      }
      printf(" leaves for looop.....\n\n");
    
      //det num rides. BFS
      for( i = 1; i < n + 1; i++) {
       //enters for...
       printf("\n Empty for...");
       ans++;
    
          BFS(A[i])
       int k = 0;
       int j = A[i][0];
    
       
       printf("\nEnd while....");
       printf("\nans: %d", ans);
      next: ;
       for(k = 1; k < n+1; k++)
        A[i][1] = 0;
      }
      printf("\nEnd problem....");
        
      end: ;
      printf(" %d", ans);
        }
    
        return 0;
    }
    Ahm, what is not working as you expect it to?

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    How To Ask Questions The Smart Way

    Code:
    //
      if( n == -1) {
       goto end;
      }
    You really shouldn't be using "goto" - especially the way it's being used here.

  4. #4
    Registered User
    Join Date
    Dec 2011
    Location
    Namib desert
    Posts
    94
    void bfs() will never work (undeclared variables) .... duh

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Depth First Search problem
    By UltimoBrah in forum C Programming
    Replies: 1
    Last Post: 03-12-2013, 11:18 AM
  2. Linear Search Problem
    By Taka in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 04:11 AM
  3. problem in binary search
    By LINUX in forum C++ Programming
    Replies: 1
    Last Post: 01-28-2009, 08:50 AM
  4. Problem with Search function
    By tboy in forum C Programming
    Replies: 5
    Last Post: 11-24-2004, 09:19 AM
  5. Search Problem
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-21-2002, 01:49 PM