Exemplo n.º 1
0
        public void Connect(T vertex1, T vertex2)
        {
            if (vertex1.Equals(vertex2))
            {
                throw new ArgumentException("Cant connect vertice to itself");
            }
            IVertex <T> first  = null;
            IVertex <T> second = null;

            foreach (var data in this._vertices)
            {
                if (data.Value.Equals(vertex1))
                {
                    first = data;
                    continue;
                }
                if (data.Value.Equals(vertex2))
                {
                    second = data;
                    continue;
                }
                if (first != null && second != null)
                {
                    break;
                }
            }
            if (first == null || second == null)
            {
                throw new ArgumentException("Vertices must be in graph");
            }
            if (this._vertices.Contains(first) && this._vertices.Contains(second))
            {
                if (first.Contains(second))
                {
                    throw new ArgumentException("Vertices are already connected");
                }
                first.Connect(second);
                EdgesCount++;
            }
            else
            {
                throw new ArgumentException("Vertices must be in graph");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Connects vertices in graph
 /// </summary>
 /// <param name="vertex1"></param>
 /// <param name="vertex2"></param>
 public void Connect(IVertex <T> vertex1, IVertex <T> vertex2)
 {
     if (vertex2.Equals(vertex1))
     {
         throw new ArgumentException("Cant connect vertice to itself");
     }
     if (this._vertices.Contains(vertex1) && this._vertices.Contains(vertex2))
     {
         if (vertex1.Contains(vertex2))
         {
             throw new ArgumentException("Vertices are already connected");
         }
         vertex1.Connect(vertex2);
         EdgesCount++;
     }
     else
     {
         throw new ArgumentException("Vertices must be in graph");
     }
 }