Exemplo n.º 1
0
        public void Add(Vertex <T> vertex2Add)
        {
            if (vertex2Add == null)
            {
                throw new ArgumentNullException(nameof(vertex2Add));
            }
            if (IsEmpty)
            {
                head = new VerticeNode <T>(vertex2Add);
                head.SetVertexID(0);
                return;
            }
            var currentNode = head;

            while (!currentNode.Contains(vertex2Add) && currentNode.Next != null)
            {
                currentNode = currentNode.Next;
            }
            if (currentNode.Contains(vertex2Add))
            {
                throw new Exception("Вершина уже содержится в списке");
            }
            currentNode.Next = new VerticeNode <T>(vertex2Add);
            currentNode.Next.SetVertexID(currentNode.V_ID + 1);
        }
Exemplo n.º 2
0
        public void Remove(Vertex <T> vertex2Remove)
        {
            if (vertex2Remove == null)
            {
                throw new ArgumentNullException(nameof(vertex2Remove));
            }
            if (IsEmpty)
            {
                throw new Exception("Список пуст");
            }
            var currentNode = head;

            if (head.Contains(vertex2Remove))
            {
                head = head.Next;
                head.SetVertexID(0);
                currentNode = head;
            }
            else
            {
                while (currentNode.Next != null && !currentNode.Next.Contains(vertex2Remove))
                {
                    currentNode = currentNode.Next;
                }
                if (currentNode.Next == null)
                {
                    throw new Exception("Вершина не содержится в списке");
                }
                currentNode.Next = currentNode.Next.Next;
            }
            while (currentNode.Next != null)
            {
                currentNode.Next.SetVertexID(currentNode.V_ID + 1);
                currentNode = currentNode.Next;
            }
        }
Exemplo n.º 3
0
 public VerticeNode(Vertex <T> vertex, VerticeNode <T> next)
 {
     this.Vertex = vertex;
     Next        = next;
 }
Exemplo n.º 4
0
 public VerticesSetList()
 {
     head = null;
 }
Exemplo n.º 5
0
 public VerticeNode(Vertex <T> vertex)
 {
     this.Vertex = vertex;
     Next        = null;
 }