コード例 #1
0
        private void DFS(Digraph digraph, Int32 vertice)
        {
            this._reachableFromSourceMap[vertice] = true;

            foreach (Int32 adjacentVertice in digraph.GetAdjacentVertices(vertice))
            {
                if (!this._reachableFromSourceMap[adjacentVertice])
                {
                    this.DFS(digraph, adjacentVertice);
                }
            }
        }
コード例 #2
0
        private void DFS(Digraph digraph, Int32 vertice)
        {
            this._visited[vertice] = true;
            this._ids[vertice]     = this.Count;

            foreach (Int32 adjacent in digraph.GetAdjacentVertices(vertice))
            {
                if (!this._visited[adjacent])
                {
                    this.DFS(digraph, adjacent);
                }
            }
        }
コード例 #3
0
        private void DFS(Digraph graph, Int32 vertice)
        {
            this._visited[vertice] = true;
            this._pre[vertice]     = this._preCounter++;
            this._preOrder.Enqueue(vertice);

            foreach (Int32 adjacent in graph.GetAdjacentVertices(vertice))
            {
                if (!this._visited[adjacent])
                {
                    this.DFS(graph, adjacent);
                }
            }

            this._postOrder.Enqueue(vertice);
            this._post[vertice] = this._postCounter++;
        }
コード例 #4
0
        private void DFS(Digraph digraph, Int32 vertice)
        {
            this._onStack[vertice] = true;
            this._visited[vertice] = true;

            foreach (Int32 adjacent in digraph.GetAdjacentVertices(vertice))
            {
                if (this.HasCycle)
                {
                    return;
                }

                // The cycle occurrs when an adjacent vertice is on the stack of
                // "vertices being processed".
                // If vertice A is being processed (onStack) and one of its adjacents
                // points to A again, we have a cycle.

                if (!this._visited[adjacent])
                {
                    this._edgeTo[adjacent] = vertice;

                    this.DFS(digraph, adjacent);
                }
                else if (this._onStack[adjacent])
                {
                    this._cycle = new AST.Stack <Int32>();

                    for (int i = vertice; i != adjacent; i = this._edgeTo[i])
                    {
                        this._cycle.Push(i);
                    }

                    this._cycle.Push(adjacent);
                    this._cycle.Push(vertice);
                }
            }

            // If we fully processed a vertice, it means the vertice is no more on
            // the stack.

            this._onStack[vertice] = false;
        }