Reputation: 25
I implemented the structure of the graph in the programming language c++, which contains the number of nodes, a array of strings in which the information contents are placed, as well as the adjacency matrix.
typedef struct Graph
{
int n;
string nodes[MAX];
double ms[MAX][MAX];
}GRAPH;
I want to make an algorithm for DFS graph traversal, I made it but there is an error.
void dfs(GRAPH* g)
{
int visit[MAX] = {};
void dfs_visit(int u) //Here is error: Expected ;
{
int v;
cout << g->nodes[u];
visit[u] = 1;
for (v = 0; v < g->n; v++)
{
if (g->ms[u][v] && !visit[v])
dfs_visit(v);
}
dfs_visit(0);
}
}
In the programming language c++
gives me an error that I need ;
function code dfs_visit
? Can someone help me how to solve this?
Thanks in advance!
Upvotes: 0
Views: 83
Reputation: 20575
You need to decide which node you want to start searching from.
Here is the general plan for a recursive graph searching code
main function
recursive function
Upvotes: 0