Example #1
0
        public Graph GraphUnion(Graph g2)
        {
            Graph out_gr = new Graph(this);

            if (this.weighted != g2.weighted)
            {
                Console.WriteLine("Взвешенность обоих графов должна быть одинаковой!");
                return(new Graph());
            }
            else
            {
                if (this.oriented || g2.oriented)
                {
                    out_gr.oriented = true;
                }
                foreach (string ver in g2.vertices.Keys)
                {
                    out_gr.AddVertexWithoutConsole(ver);
                }
                foreach (var key in g2.vertices)
                {
                    foreach (var val in key.Value)
                    {
                        out_gr.AddEdgeWithoutConsole(key.Key, val.Key, val.Value);
                    }
                }
                return(out_gr);
            }
        }