Je veux atteindre le nœud Y de cet arbre mais cet arbre de traversée de code arbre entier. Quels changements dois-je faire pour atteindre mon objectif? comment montrer le chemin parcouru à chaque étape de la traversée? J'utilise la profondeur première recherche. merci pour toute aide.profondeur premier algorithme de recherche
class Graph
{
int V; // No. of vertices
list<int> *adj;
void DFSUtil(int v, bool visited[]);
public:
Graph(int V);
void addEdge(int v, int w);
void DFS(int v);
};
Graph::Graph(int V)
{
this->V = V;
adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
adj[v].push_back(w); // Add w to v’s list.
}
void Graph::DFSUtil(int v, bool visited[])
{
visited[v] = true;
cout << v << " ";
list<int>::iterator i;
for (i = adj[v].begin(); i != adj[v].end(); ++i)
if (!visited[*i])
DFSUtil(*i, visited);
}
void Graph::DFS(int v)
{
bool *visited = new bool[V];
for (int i = 0; i < V; i++)
visited[i] = false;
DFSUtil(v, visited);
}
int main()
{
Graph g(25);
g.addEdge(0, 1);
g.addEdge(0, 2);
//...
return 0;
}
Des devoirs copiés de quelqu'un? : ( – Starl1ght
@ Starl1ght d'ici peut-être: http://www.geeksforgeeks.org/depth-first-traversal-for-a-graph/ –
"Je sais comment faire ABC Comment puis-je faire A?" Où avez-vous obtenir ce code? Si vous l'avez écrit vous-même, la réponse devrait être triviale – user463035818