DFS CODE ERROR?

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


DFS CODE ERROR?



ALGORITHM IS GIVEN BELOW ..



DFS(G)



for each vertex u ∈ G.V



u.color = WHITE



u.pi = NIL



time = 0



for each vertex u ∈ G.V



if u.color == WHITE



DFS-VISIT(G,u)



DFS-VISIT(G,u)



time = time + 1



u.d = time



u.color = GRAY



for each v ∈ G.Adj[u]



if v.color == WHITE



v.pi = u



DFS-VISIT(G,v)



u.color = BLACK



time = time + 1



u.f = time



I TRIED TO CODE THIS ALGORITHM BUT THERE IS SOME ERROR !


#include<bits/stdc++.h>
using namespace std;

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define SIZE 100

int Time;

int adj[SIZE][SIZE];
int color[SIZE];
int parent[SIZE];

int d[SIZE];

void dfs_Visit(int G, int u)
{
Time = Time++;
d[u]=Time;
color[u]=GRAY;

for(int i=0; i<G; i++)
{
int v = i;
if(color[v] == WHITE)
{
parent[v] = u;
dfs_Visit(G,u);
}
}
color[u] = BLACK;

Time++;
cout << u << " ";

}


void dfs(int G)
{
for(int i = 0 ; i < G ; i++)
{
color[i] = WHITE;
parent[i]=NULL;
}

Time=0;

cout << "DFS is ";
for(int i = 0 ; i<G ; i++)
{
if(color[i] == WHITE)
{
dfs_Visit(G,i);
}
}
}


int main()
{
int vertex;
int edge;
cout<<"VERTEX & Edge : ";
cin >> vertex >> edge;
cout << "Vertex is : " << vertex <<endl;
cout << "Edge is : " << edge <<endl;

int node1,node2;
for(int i = 0 ; i< edge ; i++)
{
cout<<"EDGE "<<i<<": ";
cin >> node1 >> node2;
adj[node1][node2] = 1;
adj[node2][node1] = 1;

}
dfs(vertex);
}



CAN ANYONE HELP ME OUT?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

QFlJ2qdWqqzVTOptgIYiV,dNaY1VSJoGe3pLpq1,4JEL4RoxgqOXJ0blZGwlsD 3tsj,71b5SqbRG
Zi kC5hzLEgIG,Hou0uSBGDHjWptbSH7uy 1dA,9afJHAqSU7mQqmDq3BwiMn83vU5gc3sJiNc

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham