コード例 #1
0
 private void DepthFirstSeach( Graph graph, int sourceVertex )
 {
     _marked[sourceVertex] = true;
      foreach ( int vertex in graph.Adjacent( sourceVertex ) )
      {
     if ( !_marked[vertex] )
     {
        _edgeTo[vertex] = sourceVertex;
        DepthFirstSeach( graph, vertex );
     }
      }
 }
コード例 #2
0
        /// <summary>
        /// Computes a path between the specified sourceVertex and every other vertex in the Graph
        /// </summary>
        /// <param name="graph">The Graph</param>
        /// <param name="sourceVertex">The source vertex to compute a path from</param>
        /// <exception cref="ArgumentException">Thrown on null or invalid Graph</exception>
        public DepthFirstPaths( Graph graph, int sourceVertex )
        {
            if ( graph == null || graph.NumberOfVertices < 0 )
             {
            throw new ArgumentException( "Invalid Graph", "graph" );
             }

             _sourceVertex = sourceVertex;
             _edgeTo = new int[graph.NumberOfVertices];
             _marked = new bool[graph.NumberOfVertices];
             DepthFirstSeach( graph, sourceVertex );
        }