/// <summary> /// Adds an item before the given item. /// </summary> /// <param name="pre"></param> /// <param name="value"></param> /// <returns></returns> public bool AddBefore(T pre, T value) { if (value == null) { throw new ArgumentException("Value cannot be null."); } IterableLinkedListNodeLink <T> node = this.FindNode(pre); if (node == null) { return(false); } IterableLinkedListNode <T> iterableLinkedListNode = new IterableLinkedListNode <T>(value, node.Child); if (node.Parent == null) { this.root = iterableLinkedListNode; } else { node.Parent.Next = iterableLinkedListNode; } return(true); }
/// <summary> /// Adds an item after the given item. /// </summary> /// <param name="pre"></param> /// <param name="value"></param> /// <returns></returns> public bool AddAfter(T pre, T value) { if (value == null) { throw new ArgumentException("Value cannot be null."); } IterableLinkedListNodeLink <T> node = this.FindNode(pre); if (node == null) { return(false); } IterableLinkedListNode <T> iterableLinkedListNode = new IterableLinkedListNode <T>(value, node.Child.Next); node.Child.Next = iterableLinkedListNode; if (node.Child == this.tail) { this.tail = iterableLinkedListNode; } return(true); }
/// <summary> /// Removes an item with the given value. /// </summary> /// <param name="value"></param> /// <returns></returns> public bool Remove(T value) { if (value == null) { throw new ArgumentException("Value cannot be null."); } IterableLinkedListNodeLink <T> node = this.FindNode(value); if (node == null) { return(false); } if (root == node.Child) { this.root = node.Child.Next; if (this.root == null) { this.tail = null; } } if (tail == node.Child) { this.tail = node.Parent; } if (node.Parent != null) { node.Parent.Next = node.Child.Next; } return(true); }