Help with Depth First Search

This is a discussion on Help with Depth First Search within the C++ Programming forums, part of the General Programming Boards category; Code: class arc { public: int adj; int weight; arc(){} arc(int a) { adj = a; } }; int bfs(int ...

  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;
                    }
                }
            }
        }
    Name:  error.jpg
Views: 162
Size:  24.2 KB

    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
    2,698
    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,296
    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, 11:51 AM
  2. graph (depth-search) question
    By l2u in forum C++ Programming
    Replies: 1
    Last Post: 11-05-2008, 06:51 AM
  3. File Search - more in depth help needed
    By RoD in forum C++ Programming
    Replies: 1
    Last Post: 12-09-2002, 04:48 AM
  4. Depth-First Search using matrices
    By supaben34 in forum C++ Programming
    Replies: 9
    Last Post: 11-02-2002, 12:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21