public static VertexCollection InVertexTree(IBidirectionalVertexAndEdgeListGraph g, IVertex v, int maxDepth)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (v == null)
     {
         throw new ArgumentNullException("v");
     }
     HeightFirstSearchAlgorithm algorithm = new HeightFirstSearchAlgorithm(g);
     algorithm.BackEdge += new EdgeEventHandler(null, (IntPtr) dfs_BackEdge);
     VertexRecorderVisitor visitor = new VertexRecorderVisitor();
     visitor.Vertices.Add(v);
     algorithm.TreeEdge += new EdgeEventHandler(visitor, (IntPtr) this.RecordTarget);
     algorithm.MaxDepth = maxDepth;
     algorithm.Initialize();
     algorithm.Visit(v, 0);
     return visitor.Vertices;
 }
        /// <summary>
        /// Records all the vertices that are part of the out-subtree of v
        /// </summary>
        /// <param name="g">visited graph</param>
        /// <param name="v">root vertex</param>
        /// <param name="maxDepth">Maximum exploration depth</param>
        /// <returns></returns>
        public static VertexCollection OutVertexTree(
            IVertexListGraph g,
            IVertex v,
            int maxDepth
            )
        {
            if (g==null)
                throw new ArgumentNullException("g");
            if (v==null)
                throw new ArgumentNullException("v");

            DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g);
            dfs.BackEdge +=new EdgeEventHandler(dfs_BackEdge);
            VertexRecorderVisitor vis =new VertexRecorderVisitor();
            vis.Vertices.Add(v);
            dfs.TreeEdge +=new EdgeEventHandler(vis.RecordTarget);

            dfs.MaxDepth = maxDepth;
            dfs.Initialize();
            dfs.Visit(v,0);

            return vis.Vertices;
        }