public override bool Contains(T value) { Assertion.Pre(value != null); DoublyLinkedListElement <T> finger = this.head; while (finger != null && !value.Equals(finger.GetValue())) { finger = finger.GetNext(); } return(finger != null); }
public override T Remove(T value) { Assertion.Pre(value != null); DoublyLinkedListElement <T> finger = this.head; while (finger != null && !value.Equals(finger.GetValue())) { finger = finger.GetNext(); } if (finger == null) { return(default(T)); } if (finger.GetPrevious() != null) { finger.GetPrevious().SetNext(finger.GetNext()); } else { this.head = finger.GetNext(); } if (finger.GetNext() != null) { finger.GetNext().SetPrevious(finger.GetPrevious()); } else { this.tail = finger.GetPrevious(); } return(finger.GetValue()); }
public override T RemoveFromTail() { Assertion.Pre(this.tail != null); DoublyLinkedListElement <T> oldTail = this.tail; this.tail = this.tail.GetPrevious(); if (this.tail == null) { this.head = null; } else { this.tail.SetNext(null); } return(oldTail.GetValue()); }
public override T RemoveFromHead() { Assertion.Pre(this.head != null); DoublyLinkedListElement <T> oldHead = this.head; this.head = this.head.GetNext(); if (this.head == null) { this.tail = null; } else { this.head.SetPrevious(null); } return(oldHead.GetValue()); }
public void TestSetGetValue() { Assert.AreEqual(1, (int)element.GetValue()); element.SetValue(2); Assert.AreEqual(2, (int)element.GetValue()); }