public void Delete(T value) { if (this.startNode == null) { throw new InvalidOperationException("Cannot call delete on an empty list"); } else if (this.startNode.IsEqual(value)) { if (this.startNode == this.lastNode) { this.lastNode = null; } this.startNode = this.startNode.Next; } else { var node = this.startNode; while (node.HasNext) { if (node.Next.IsEqual(value)) { if (this.lastNode == node.Next) { this.lastNode = node; } node.Next = node.Next.Next; return; } node = node.Next; } throw new InvalidOperationException("No element found to delete with value " + value); } }
public void AddFirst(T value) { VerifyCollectionHasRoom(); ILinkedListNode <T> node = new LinkedListNode <T>(value); // If first is null than this linked list is empty and we should set First and Last to the new node. if (First == null) { First = node; Last = node; } else { // We need to set the current First node as the next node of the current node and then set Previous // of the current First node to the new node. node.Next = First; First.Previous = node; First = node; } Count++; }
public RemoveLinkedListOperation <T> Remove(ILinkedListNode <T> node) => Remove <T>(node);
public AddBeforeLinkedListOperation <T> AddBefore(ILinkedListNode <T> node, T value) => AddBefore <T>(node, value);
public AddAfterLinkedListOperation <T> AddAfter(ILinkedListNode <T> node, T value) => AddAfter <T>(node, value);
public void AddNode(ILinkedListNode <string> node, string token) { throw new System.NotImplementedException(); }
public static void AssertLinkedList <TNode>(ILinkedListNode <TNode> first, ILinkedListNode <TNode> last) where TNode : class, ILinkedListNode <TNode> { if (first == null) { Debug.Assert(last == null); return; } Debug.Assert(last != null); if (first == last) { Debug.Assert(first.Next == null); Debug.Assert(last.Previous == null); } if (first.Next != null) { Debug.Assert(first.Next.Previous == first); } else { Debug.Assert(first == last); } if (last.Previous != null) { Debug.Assert(last.Previous.Next == last); } else { Debug.Assert(first == last); } { var nodes = new HashSet <ILinkedListNode <TNode> >(); var prev = first; var curr = first.Next; var added = nodes.Add(prev); Debug.Assert(added); while (curr != null) { Debug.Assert(nodes.Add(curr)); Debug.Assert(curr.Previous == prev); prev = curr; curr = curr.Next; } Debug.Assert(prev == last); } { var nodes = new HashSet <ILinkedListNode <TNode> >(); var prev = last; var curr = last.Previous; var added = nodes.Add(prev); Debug.Assert(added); while (curr != null) { Debug.Assert(nodes.Add(curr)); Debug.Assert(curr.Next == prev); prev = curr; curr = curr.Previous; } Debug.Assert(prev == first); } }
public void Dispose() { Next = null; Previous = null; list = null; }
public ILinkedList <T> AddBefore(ILinkedListNode <T> target, ILinkedListNode <T> node) { throw new NotImplementedException(); }
protected void AddHandler(MessageHandler handler) { _tail.InsertAfter(handler); _tail = handler; }
public Receivable() { _tail = this; }
public SinglyLinkedList() { this.startNode = null; this.lastNode = null; }
public void AddNode(ILinkedListNode <IUIBinder> node, IUIBinder token) { throw new System.NotImplementedException(); }
public void Add(ILinkedListNode <T> node) { Next.Previous = node; Next = node; }
public bool Remove(ILinkedListNode <T> node) { throw new NotImplementedException(); }
public ILinkedList <T> AddAfter(ILinkedListNode <T> target, T value) { throw new NotImplementedException(); }
public void Remove(ILinkedListNode <T> node) { var goodNode = NodeValidation(node); DoRemove(goodNode); }
public ILinkedList <T> Append(ILinkedListNode <T> node) { throw new NotImplementedException(); }
public void Find_Should_ReturnCorrectLinkedListNode(string[] inputItems, string itemToSearch, ILinkedListNode expectedResult) { foreach (string item in inputItems) { linkedList.Add(item); } ILinkedListNode actualResult = linkedList.Find(itemToSearch); Assert.Equal(expectedResult?.Value, actualResult?.Value); }