/// <summary>
        /// Remove an existing vertex from this graph.
        /// Time complexity: O(V) where V is the number of verticles.
        /// </summary>
        /// <param name="vertex"></param>
        /// <returns></returns>
        public void RemoveVertex(T vertex)
        {
            if (vertex == null)
            {
                throw new ArgumentNullException();
            }

            if (!Verticles.ContainsKey(vertex))
            {
                throw new Exception("Vertex is not in this graph.");
            }

            foreach (var v in Verticles[vertex].Edges)
            {
                v.Edges.Remove(Verticles[vertex]);
            }
            Verticles.Remove(vertex);
        }
示例#2
0
        /// <summary>
        /// Remove the given vertex.
        /// Time complexity: O(V) where V is the number of verticles.
        /// </summary>
        public void RemoveVertex(T value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            if (!Verticles.ContainsKey(value))
            {
                throw new Exception("Vetex is not in this  graph.");
            }

            foreach (var vertex in Verticles[value].InEdges)
            {
                vertex.Key.OutEdges.Remove(Verticles[value]);
            }

            foreach (var vertex in Verticles[value].OutEdges)
            {
                vertex.Key.InEdges.Remove(Verticles[value]);
            }
            Verticles.Remove(value);
        }