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); }
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; } }