public void RemoveFirst() { if (First != null) { Count--; First.List = null; } First = First?.Next; if (First != null) { First.Previous.Next = null; First.Previous = null; } }
public void RemoveLast() { if (Last != null) { Count--; Last.List = null; } Last = Last?.Previous; if (Last != null) { Last.Next.Previous = null; Last.Next = null; } }
public void AddLast(MyLinkedListNode <T> Value) { if (Value.List == this) { throw new InvalidOperationException(); } if (Last == null) { InicializeFirstElement(Value); return; } Count++; Value.List = this; Last.Next = Value; Value.Previous = Last; Last = Value; }
public void Remove(MyLinkedListNode <T> Insert) { if (Insert.List != this) { throw new ArgumentException(); } Count--; Insert.List = null; if (Insert == Last) { Last = Insert.Previous; } if (Insert == First) { First = Insert.Next; } if (Insert.Next == null && Insert.Previous == null) { Clear(); } else if (Insert.Next == null) { Insert.Previous.Next = null; } else if (Insert.Previous == null) { Insert.Next.Previous = null; } else { Insert.Next.Previous = Insert.Previous; Insert.Previous.Next = Insert.Next; } }
public void AddBefore(MyLinkedListNode <T> Current, MyLinkedListNode <T> Insert) { var currPrevious = Current.Previous; if (Insert.List == this) { throw new InvalidOperationException(); } if (currPrevious == null) { AddFirst(Insert); return; } Count++; Insert.List = this; Current.Previous = Insert; Insert.Next = Current; Insert.Previous = currPrevious; currPrevious.Next = Insert; }
public void Reset() { Curr = StartPosition; }
private void InicializeFirstElement(T Value) { MyLinkedListNode <T> Insert = new MyLinkedListNode <T>(Value); InicializeFirstElement(Insert); }
public void AddBefore(MyLinkedListNode <T> Current, T Value) { var Insert = new MyLinkedListNode <T>(Value); AddBefore(Current, Insert); }
public void AddLast(T Value) { var Insert = new MyLinkedListNode <T>(Value); AddLast(Insert); }