8 Graph traversals Recursive depth-first traversal A recursive implementation uses the call stack for memory: void Graph::depth_first_traversal( Vertex *first ) const { Hash_table hash; hash.insert( first ); first->depth_first_traversal( hash ); } void Vertex::depth_first_traversal( Hash_table hash ) const { // Perform an operation on this for ( Vertex *v : adjacent_vertices() ) { if ( !hash.member( v ) ) { hash.insert( v ); v->depth_first_traversal( hash ); }
{}