public override T Remove(T value) { Assertion.Pre(value != null); SinglyLinkedListElement <T> finger = this.head; SinglyLinkedListElement <T> previous = null; while (finger != null && !value.Equals(finger.GetValue())) { previous = finger; finger = finger.GetNext(); } if (finger == null) { return(default(T)); } if (previous == null) { this.head = finger.GetNext(); } else { previous.SetNext(finger.GetNext()); } this.count--; return(finger.GetValue()); }
public override T RemoveFromTail() { Assertion.Pre(this.tail != null); SinglyLinkedListElement <T> finger = this.tail; SinglyLinkedListElement <T> oldTail = this.tail; while (finger.GetNext() != this.tail) { finger = finger.GetNext(); } if (finger == this.tail) { this.tail = null; } else { finger.SetNext(this.tail.GetNext()); this.tail = finger; } this.count--; return(oldTail.GetValue()); }
public override T RemoveFromTail() { Assertion.Pre(this.head != null); SinglyLinkedListElement <T> previous = null; SinglyLinkedListElement <T> finger = this.head; while (finger.GetNext() != null) { previous = finger; finger = finger.GetNext(); } if (previous == null) { this.head = null; } else { previous.SetNext(finger.GetNext()); } this.count--; return(finger.GetValue()); }
public void TestSetGetNext() { Assert.AreEqual(null, element.GetNext()); SinglyLinkedListElement <int> e = new SinglyLinkedListElement <int>(2, element); Assert.AreEqual(element, e.GetNext()); SinglyLinkedListElement <int> e2 = new SinglyLinkedListElement <int>(3, null); element.SetNext(e2); Assert.AreEqual(e2, element.GetNext()); }
public override T RemoveFromHead() { Assertion.Pre(this.head != null); SinglyLinkedListElement <T> oldHead = this.head; this.head = this.head.GetNext(); this.count--; return(oldHead.GetValue()); }
public override T PeekTail() { Assertion.Pre(this.head != null); SinglyLinkedListElement <T> finger = this.head; while (finger.GetNext() != null) { finger = finger.GetNext(); } return(finger.GetValue()); }
public override bool Contains(T value) { Assertion.Pre(value != null); SinglyLinkedListElement <T> finger = this.head; while (finger != null && !value.Equals(finger.GetValue())) { finger = finger.GetNext(); } return(finger != null); }
public override void AddToHead(T value) { SinglyLinkedListElement <T> newHead = new SinglyLinkedListElement <T>(value); if (this.tail == null) { this.tail = newHead; } else { SinglyLinkedListElement <T> head = this.tail.GetNext(); newHead.SetNext(head); } this.tail.SetNext(newHead); this.count++; }
public override T RemoveFromHead() { Assertion.Pre(this.tail != null); SinglyLinkedListElement <T> head = this.tail.GetNext(); if (this.tail == head) { this.tail = null; } else { this.tail.SetNext(head.GetNext()); } this.count--; return(head.GetValue()); }
public override void AddToTail(T value) { SinglyLinkedListElement <T> newTail = new SinglyLinkedListElement <T>(value); if (this.head == null) { this.head = newTail; } else { SinglyLinkedListElement <T> finger = this.head; while (finger.GetNext() != null) { finger = finger.GetNext(); } finger.SetNext(newTail); } this.count++; }
public override bool Contains(T value) { Assertion.Pre(value != null); SinglyLinkedListElement <T> finger = this.tail; if (finger == null) { return(false); } do { if (value.Equals(finger.GetValue())) { return(true); } finger = finger.GetNext(); } while (finger != this.tail); return(false); }
public override void AddToTail(T value) { AddToHead(value); this.tail = this.tail.GetNext(); }
public void SetNext(SinglyLinkedListElement <T> next) { this.next = next; }
public void TestSetup() { element = new SinglyLinkedListElement <int>(1); }
public SinglyLinkedListElement(T value, SinglyLinkedListElement <T> next) { this.value = value; this.next = next; }
public override void AddToHead(T value) { this.head = new SinglyLinkedListElement <T>(value, this.head); this.count++; }
public override void Clear() { this.head = null; this.count = 0; }
public override void Clear() { this.tail = null; this.count = 0; }