Пример #1
0
        public SymbolDigraph(List <Tuple <string, string> > input, bool allowSelfLoops = true, bool allowParallelEdges = true)
        {
            _st = new Dictionary <string, int>();
            foreach (var connection in input)
            {
                if (!_st.ContainsKey(connection.Item1))
                {
                    _st.Add(connection.Item1, _st.Count);
                }

                if (!_st.ContainsKey(connection.Item2))
                {
                    _st.Add(connection.Item2, _st.Count);
                }
            }
            _keys = new List <string>();
            foreach (var key in _st.Keys)
            {
                _keys.Add(key);
            }
            Digraph = new Digraph(_st.Count, allowSelfLoops, allowParallelEdges);
            foreach (var connection in input)
            {
                int v = _st[connection.Item1];
                int u = _st[connection.Item2];
                Digraph.AddEdge(v, u);
            }
        }
Пример #2
0
        public Digraph Reverse()
        {
            var reversedGraph = new Digraph(V, _allowSelfLoops, _allowParallelEdges);

            for (int v = 0; v < V; v++)
            {
                foreach (var w in Adjacent(v))
                {
                    reversedGraph.AddEdge(w, v);
                }
            }
            return(reversedGraph);
        }