public void Remove(object value) { var current = this.head; while (current != null) { if (current.Value.Equals(value)) { this.Count--; var prev = current.Prev; var next = current.Next; if (current != this.head) { prev.Next = next; } else { this.head = next; } if (current != this.tail) { next.Prev = prev; } else { this.tail = prev; } } current = current.Next; } }
public void AddTail(object value) { var newNode = new CoolNode(value); if (this.Count == 0) { this.tail = this.head = newNode; } else { var oldTail = this.tail; oldTail.Next = newNode; newNode.Previous = oldTail; this.tail = newNode; } this.Count++; }
public void AddHead(object value) { var newNode = new CoolNode(value); if (this.Count == 0) { this.head = this.tail = newNode; } else { var oldHead = this.head; oldHead.Previous = newNode; newNode.Next = oldHead; this.head = newNode; } this.Count++; }
public T RemoveHead() { this.ValidateIfListIsEmpty(); var value = this._head.Value; if (this._head == this._tail) { this._head = null; this._tail = null; } else { var newHead = this._head.Next; newHead.Previous = null; this._head.Next = null; this._head = newHead; } this.Count--; return(value); }
public object RemoveTail() { ValidateIfIsEmpty(); var oldTail = this.tail; if (this.head == this.tail) { this.head = null; this.tail = null; } else { var newTail = oldTail.Prev; this.tail = newTail; this.tail.Next = null; } this.Count--; return(oldTail.Value); }
public object RemoveHead() { ValidateIfIsEmpty(); var oldHead = this.head; if (this.head == this.tail) { this.head = null; this.tail = null; } else { var newHead = this.head.Next; this.head = newHead; this.head.Prev = null; } this.Count--; return(oldHead.Value); }
public void Remove(object value) { var currentNode = this.head; while (currentNode != null) { var nodeValue = currentNode.Value; if (nodeValue.Equals(value)) { this.Count--; var prevNode = currentNode.Previous; var nextNode = currentNode.Next; if (prevNode != null) { prevNode.Next = nextNode; } if (nextNode != null) { nextNode.Previous = prevNode; } if (this.head == currentNode) { this.head = nextNode; } if (this.tail == currentNode) { this.tail = prevNode; } } currentNode = currentNode.Next; } }
public object RemoveTail() { this.ValidateIfListIsEmpty(); var value = this.tail.Value; if (this.head == this.tail) { this.head = null; this.tail = null; } else { var oldTail = this.tail; var newTail = this.tail.Previous; this.tail.Previous = null; this.tail = newTail; } this.Count--; return(value); }
public void Clear() { this.head = null; this.tail = null; this.Count = 0; }