Thread: Help with Depth First Search

  1. #1
    "PALINDROME"
    Join Date
    Nov 2010
    Posts
    59

    Help with Depth First Search

    Code:
    class arc
    {
      public:
        int adj;
        int weight;
        arc(){}
        arc(int a)
        {
            adj = a;
        }
    };
    
    int bfs(int v,int n) //using queues
        {
            int i, front, rear;
            int que[20];
            front = rear =  - 1;
    
            cout << v;
            visited[v] = true;
            rear++;
            front++;
            que[rear] = v;
    
            while (front <= rear)
            {
                v = que[front];
                front++;
                for (i = 1; i <= n; i++)
                {
                    if ((arcs[v][i] == 1) && (visited[i] == false)) //error line
                    {
                        cout << i;
                        visited[i] = true;
                        rear++;
                        que[rear] = i;
                    }
                }
            }
        }
    Help with Depth First Search-error-jpg

    can someone help me with my problem? please i really2x need all your help thanks advance

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Since you seem to be using quite a few global variables, you will need to post the smallest possible complete program that illustrates your problem. For example how is arcs defined? How is visited defined?

    Jim

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You're trying to do breadth first search, not depth first.
    Misleading thread title.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Depth-first search & TSP
    By Cpro in forum C++ Programming
    Replies: 12
    Last Post: 12-13-2008, 12:51 PM
  2. graph (depth-search) question
    By l2u in forum C++ Programming
    Replies: 1
    Last Post: 11-05-2008, 07:51 AM
  3. File Search - more in depth help needed
    By RoD in forum C++ Programming
    Replies: 1
    Last Post: 12-09-2002, 05:48 AM
  4. Depth-First Search using matrices
    By supaben34 in forum C++ Programming
    Replies: 9
    Last Post: 11-02-2002, 01:53 PM