change extern visitNode function to a parameter of bfs function