public T RemoveFirst() { if (this.Count == 0) { throw new InvalidOperationException("List is empty!"); } T removedElement = this.head.Value; if (this.Count == 1) { this.head = null; this.tail = null; } else { ListNode <T> newHead = this.head.NextNode; newHead.PreviousNode = null; this.head = newHead; } this.Count--; return(removedElement); }
public T RemoveLast() { //има ли head дай ми валю, ако няма head върни ми null в променливата if (this.Count == 0) { throw new InvalidOperationException("List is empty!"); } T removedElement = this.tail.Value; if (this.Count == 1) { this.head = null; this.tail = null; } else { ListNode <T> newTail = this.tail.PreviousNode; newTail.NextNode = null; this.tail = newTail; } this.Count--; return(removedElement); }