Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. template<typename C>
  2. void  DFS (const Grafo<C> & g, int origen, map<int, char> & estado, bool & ciclo, list<int> & ciclos, list<list<int>> & todos_ciclos){
  3.     list<Grafo<int>::Arco> adyacentes;
  4.     g.devolver_adyacentes(origen,adyacentes);
  5.     typename list<Grafo<int>::Arco>::const_iterator it;
  6.     estado[origen] = 'a';
  7.     for (it = adyacentes.begin(); it != adyacentes.end(); it++){
  8.         if (estado[it->devolver_adyacente()] == 'a'){
  9.             ciclo=true;
  10.         }
  11.         else if (estado[it->devolver_adyacente()] == 'b'){
  12.             cout << it->devolver_adyacente();
  13.             ciclos.push_back(it->devolver_adyacente());
  14.             DFS (g, it->devolver_adyacente(),estado,ciclo,ciclos,todos_ciclos);
  15.             if (ciclo == false)
  16.                 ciclos.pop_back();
  17.             else {
  18.                     todos_ciclos.push_back(ciclos);
  19.                     ciclos.pop_back();
  20.                     ciclo=false;
  21.             }
  22.             estado[it->devolver_adyacente()] = 'b';
  23.         }
  24.     }
  25.     estado[origen] = 'n';
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement