algorithm - Depth first search (C++) -


i've created class contains vector of linked lists. each linked list represents vertice in graph. nodes connected linked lists considered edges between these vertices. i'm trying create dfs function graph, having trouble setting colors of vertices. realize there lot of problems code, i'm trying solve 1 in particular. dfsit() function ends in infinite loop because color attribute list isn't getting set "gray". idea why be?

void graph::dfs() {     int = 0;     while (i != myvector.size())     {          dfsit(myvector[i], myvector[i].val);         myvector[i].color = "black";         i++;     } }  void graph::dfsit(adjlist x, int root) { if (x.color == "white") {     cout << "tree edge ( " << root << "," << x.val << ") " << endl; } if (x.color == "gray") {     cout << "back edge ( " << root << "," << x.val << ") " << endl;     return; }      x.color = "gray";      adjnode *temp = new adjnode();     temp = x.front;     int = 0;     int value;     while (temp != null)     {         value = temp->getvalue();         while (i != myvector.size())         {             if (value == myvector[i].val)             {                 dfsit(myvector[i], root);             }             i++;         }         temp = temp->next;     }  } 

normaly, proper implementation of dfs rutine made stack, work also. think coloring node adjlist x , coloring not save because passing val , not ref. try changing void graph::dfsit(adjlist x, int root) void graph::dfsit(adjlist& x, int root)


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -