コード例 #1
0
ファイル: DirectedGraph.cs プロジェクト: Curlymustach/Graphs1
        public bool AddEdge(Vertex <T> start, Vertex <T> end, double weight)
        {
            Edge <T> edge = GetEdge(start, end);

            if (edge != null)
            {
                return(false);
            }

            edge = new Edge <T>(start, end, weight);

            start.AddEdge(edge);
            edges.Add(edge);
            return(true);
        }
コード例 #2
0
        public void AddEdge(string from, string to, uint weight)
        {
            if (!AdjList.ContainsKey(from))
            {
                throw new Exception($"The vertex with name {from} does not exist!");
            }
            if (!AdjList.ContainsKey(to))
            {
                throw new Exception($"The vertex with name {to} does not exist!");
            }
            Vertex fr = AdjList[from], t = AdjList[to];

            fr.AddEdge(t, weight);
            if (!directed)
            {
                t.AddEdge(fr, weight);
            }
        }