Пример #1
0
        public Vertex <T> AddVertex(Vertex <T> v)
        {
            if (string.IsNullOrEmpty(v.Name))
            {
                throw new Exception("DirectedGraph.AddVertex(): Vertex name cannot be null.");
            }

            if (_vertices.Contains(v.Name))
            {
                throw new Exception("DirectedGraph.AddVertex(): Duplicated vertex: " + v.Name);
            }
            _vertices.Add(v.Name, v);
            return(v);
        }
Пример #2
0
 private OrderedCollection <Vertex <T> > GetAdjacent(Vertex <T> v)
 {
     if (_adjacent.Contains(v))
     {
         return(_adjacent[v]);
     }
     else
     {
         OrderedCollection <Vertex <T> > adj = new OrderedCollection <Vertex <T> >();
         _adjacent.Add(v, adj);
         return(adj);
     }
 }