// Adds this element to the list, with replacing the specified element. // This is equivalent to calling the sequence: LinkBefore(Replace); replace.Unlink(); public void LinkReplace(DoubleLinkBaseAdv <T> link, DoubleLinkBaseAdv <T> replace) { Debug.Assert(link != null); Debug.Assert(replace != null); Debug.Assert(replace.List == this); if (link.IsLinked) { link.Unlink(); } link.Previous = replace.Previous; link.Next = replace.Next; if (link.Previous != null) { link.Previous.Next = link; } if (link.Next != null) { link.Next.Previous = link; } replace.Next = null; replace.Previous = null; }
// Remove link from list public void Unlink() { if (Next != null) { Next.Previous = Previous; } if (Previous != null) { Previous.Next = Next; } Next = Previous = null; }
// Adds this element to the list, after the specified element public void LinkAfter(DoubleLinkBaseAdv <T> link, DoubleLinkBaseAdv <T> after) { Debug.Assert(link != null); Debug.Assert(after != null); Debug.Assert(after.List == this); if (link.IsLinked) { link.Unlink(); } link.List = this; link.Next = after.Next; after.Next = link; link.Previous = after; if (link.Next != null) { link.Next.Previous = link; } count++; }
// Adds this element to a list, before the given element. public void LinkBefore(DoubleLinkBaseAdv <T> link, DoubleLinkBaseAdv <T> before) { Debug.Assert(link != null); Debug.Assert(before != null); Debug.Assert(before.List == this); if (link.IsLinked) { link.Unlink(); } link.List = this; link.Previous = before.Previous; before.Previous = link; link.Next = before; if (link.Previous != null) { link.Previous.Next = link; } count++; }
// Remove link from list public void Unlink(DoubleLinkBaseAdv <T> link) { Debug.Assert(link != null); Debug.Assert(link.List != this); if (link.IsLinked) { link.Unlink(); } link.List = this; if (link.Next != null) { link.Next.Previous = link.Previous; } if (link.Previous != null) { link.Previous.Next = link.Next; } link.Next = link.Previous = null; link.List = null; count--; }
// Adds this element to the list, with replacing the specified element. // This is equivalent to calling the sequence: LinkBefore(Replace); replace.Unlink(); public void LinkReplace(DoubleLinkBaseAdv <T> replace) { Debug.Assert(replace != null); Debug.Assert(List != null); List.LinkReplace(this, replace); }
// Adds this element to the list, after the specified element public void LinkAfter(DoubleLinkBaseAdv <T> after) { Debug.Assert(after != null); Debug.Assert(List != null); List.LinkAfter(this, after); }
// Adds this element to a list, before the given element. public void LinkBefore(DoubleLinkBaseAdv <T> before) { Debug.Assert(before != null); Debug.Assert(List != null); List.LinkBefore(this, before); }
// Create link without connection to the list public DoubleLinkBaseAdv(T data = null) { Data = data; Next = null; Previous = null; }
public void AddFirst(DoubleLinkBaseAdv <T> link) { LinkAfter(link, Last); }
public void AddLast(DoubleLinkBaseAdv <T> link) { LinkBefore(link, First); }
// Construct empty list public DoubleLinkedListAdv() { First = Last = Root; count = 0; }