public void SetNext(DoublyLinkedListElement <T> next) { this.next = next; if (next != null) { next.previous = this; } }
public override void AddToHead(T value) { this.head = new DoublyLinkedListElement <T>(value, null, this.head); if (this.tail == null) { this.tail = this.head; } }
public void SetPrevious(DoublyLinkedListElement <T> previous) { this.previous = previous; if (previous != null) { previous.next = this; } }
public override void AddToTail(T value) { this.tail = new DoublyLinkedListElement <T>(value, this.tail, null); if (this.head == null) { this.head = this.tail; } }
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 void TestSetGetNext() { Assert.AreEqual(null, element.GetNext()); DoublyLinkedListElement <int> e = new DoublyLinkedListElement <int>(2, null, element); Assert.AreEqual(element, e.GetNext()); Assert.AreEqual(e, element.GetPrevious()); DoublyLinkedListElement <int> e2 = new DoublyLinkedListElement <int>(3); element.SetNext(e2); Assert.AreEqual(e2, element.GetNext()); Assert.AreEqual(element, e2.GetPrevious()); }
public DoublyLinkedListElement(T value, DoublyLinkedListElement <T> previous, DoublyLinkedListElement <T> next) { this.value = value; this.previous = previous; if (previous != null) { previous.next = this; } this.next = next; if (next != null) { next.previous = this; } }
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 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 void Clear() { this.head = null; this.tail = null; }
public void TestSetup() { element = new DoublyLinkedListElement <int>(1); }