Пример #1
0
        private void DFS_iter(Graph graph, int node)
        {
            Stack <int> st = new Stack <int>();

            st.Push(node);

            while (st.Count != 0)
            {
                int v = st.Pop();
                if (Explored[v] != 2)
                {
                    st.Push(v); // ??
                    if (Explored[v] == 0)
                    {
                        Explored[v] = 1;
                    }

                    bool allAdjExplored = true;
                    foreach (int w in graph.Adjacents[v])
                    {
                        if (Explored[w] == 0)
                        {
                            allAdjExplored = false;
                            st.Push(w);
                            break;
                        }
                    }

                    if (allAdjExplored)
                    {
                        Explored[v] = 2; // v becomes finished, there are no outgoing arcs to unexplored

                        if (CurrentPass == 1)
                        {
                            timer++;
                            FTime[v] = timer;
                        }

                        else if (CurrentPass == 2)
                        {
                            if (!Leader.ContainsKey(s))
                            {
                                Leader.Add(s, 1);
                            }
                            else
                            {
                                Leader[s]++;
                            }
                        }
                        st.Pop();
                    }
                }
            }
        }