I have a program that has to create a tree from a graph, for that I have the following code:
NodoArbol<Vertice>* GrafoMatriz::getBP(bool AR, string origen){
int num_pf=1;
int indiceV = this->getIndicePorNombre(origen);
Nodo<Vertice>* nodo = new Nodo<Vertice>(this->vertices[indiceV]);
NodoArbol<Vertice>* raiz = new NodoArbol<Vertice>(nodo , num_pf);
Arbol<Vertice>* BP = new Arbol<Vertice>(raiz, AR);
Lista<bool>* Visitados = new Lista<bool>();
for(int i=0; i<this->getMaximoVertices();i++){
Visitados->add(false,Visitados);
}
Visitados->marcar(Visitados, indiceV);
raiz->addHijo(aplicarBP(AR,Visitados,origen,++num_pf));
return BP->getRaiz();
}
//Funcion que obtiene el Bosque en profundidad del grafo
NodoArbol<Vertice>* GrafoMatriz::aplicarBP(bool conAristasRetroceso,
Lista<bool>* Visitados, string origen, int num){
NodoArbol<Vertice>* nodo = nullptr;
Cola<Vertice>* adyacentes = this->getAdyacentesDeV(origen);
while(!adyacentes->vacia(adyacentes)){
int indiceW = this->getIndicePorNombre(adyacentes->getPrimero()->getDato().getNombre());
if(!(Visitados->getValor(Visitados,indiceW))){
origen = this->vertices[indiceW].getNombre();
Nodo<Vertice>* nodoHijo = new Nodo<Vertice>(this->vertices[indiceW]);
nodo = new NodoArbol<Vertice>(nodoHijo,num);
Visitados->marcar(Visitados, indiceW);
nodo->addHijo(aplicarBP(conAristasRetroceso,Visitados,origen,++num));
}else{
adyacentes->quitaDeCola(adyacentes);
}
}
return nodo;
}
In the part of adding a child I have a list to add the children of this
in class NodoArbol
:
Lista<NodoArbol<T>>* hijos;
The method is as follows:
template <class T>
void NodoArbol<T>::addHijo( NodoArbol<T>* hijo){
this->hijos->add(hijo,this->hijos);
this->num_hijos++;
}
And the add code in List is like this:
Nodo<T>* nodoNuevo = new Nodo<T>(x,nullptr);
Nodo<T>* estePrimero = lista->primero;
if (estePrimero==nullptr){
estePrimero = nodoNuevo;
estePrimero->ponerEnlace(nullptr);
lista->primero = estePrimero;
}else{
Nodo<T>* temporal = estePrimero;
while(!(temporal->getEnlace()==nullptr)){
temporal= temporal->getEnlace();
}
temporal->ponerEnlace(nodoNuevo);
}
And the node class constructor
Nodo(T x, Nodo<T>*sig)
{
dato = x;
enlace = sig;
}
Now comes the problem, when I try to add a nodoArbol
to this list I get the following error:
..\src\Nodo.h:39:9: note: no known conversion for argument 1 from 'NodoArbol<Vertice>*' to 'NodoArbol<Vertice>'
The error is thrown in this line:
Nodo<T>* nodoNuevo = new Nodo<T>(x,nullptr);
I think I have a problem regarding the references of the classes, but in this sense I do not know what to do.