Recursively, you mark each node when you cross it, and when you have nothing to explore, go back.
Something that will look
function
mark the current edge
for all it vertices
call the function on the edge that is connected with the vertice if the edge is not marked
do something with the edge (display or whatever)
once there is no vertices left return
C For example, if a graph is represented by an adjacent matrix, a length of 1000 means that there are no vertices.
void inDepth(int i)
{
int j;
edges[i] = 1;
for (j=0; j<N; j++)
{
if ((vertices[i][j]<1000) && (vertices[i][j]>0) && (edges[j]==0))
{
inDepth(j);
}
}
printf("%d ",i);
}
source
share