Advertisement
Guest User

Untitled

a guest
May 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. template <typename T>
  2. void caminosAcotados(const Grafo<T, float>& G, const T& u, float maxCoste)
  3. {
  4.     stringstream ss;
  5.     ss << u;
  6.     caminosAcotados(G, u, maxCoste, ss.str(), 0);
  7. }
  8.  
  9. template <typename T>
  10. void caminosAcotados(const Grafo<T, float>& G, const T& u, float maxCoste, string camino, int coste)
  11. {
  12.     Conjunto<Arista<T, float> > conjA = G.aristas();
  13.     cout << "<" << camino << "> Coste: " << coste << endl;
  14.     while(!conjA.esVacio())
  15.     {
  16.         Arista<T, float> a = conjA.quitar();
  17.         if((a.getOrigen() == u) && ((a.getEtiqueta() + coste) <= maxCoste))
  18.         {
  19.             stringstream ss;
  20.             ss << ", " << a.getDestino();
  21.             caminosAcotados(G, a.getDestino(), maxCoste, camino + ss.str(), coste + a.getEtiqueta());
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement