// Add first element public void AddLast(SDoubleLinkBase <DataType> link) { Debug.Assert(link != null); if (link.IsLinked) { link.Unlink(); } link.LinkAfter(Last); }
// Add last element public void AddFirst(SDoubleLinkBase <DataType> link) { Debug.Assert(link != null); if (link.IsLinked) { link.Unlink(); } link.LinkBefore(First); }
// Adds this element to the list, after the specified element public void LinkAfter(SDoubleLinkBase <DataType> after) { Debug.Assert(after != null); Next = after.Next; after.Next = this; Previous = after; if (Next != null) { Next.Previous = this; } }
// Adds this element to a list, before the given element. public void LinkBefore(SDoubleLinkBase <DataType> before) { Debug.Assert(before != null); Previous = before.Previous; before.Previous = this; Next = before; if (Previous != null) { Previous.Next = this; } }
// ==================================================================================== // Methods // ==================================================================================== // Remove link from list public void Unlink() { if (Next != null) { Next.Previous = Previous; } if (Previous != null) { Previous.Next = Next; } Next = Previous = null; }
// ==================================================================================== // Interfaces // ==================================================================================== #region IComparable public int CompareTo(SDoubleLinkBase <DataType> other) { if (other == null) { return(-1); } if (other != this) { return(-1); } return(CompareTo(other)); }
// 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(SDoubleLinkBase <DataType> replace) { Debug.Assert(replace != null); var replacePrev = replace.Previous; var replaceNext = replace.Next; Previous = replacePrev; Next = replaceNext; if (Previous != null) { Previous.Next = this; } if (Next != null) { Next.Previous = this; } replacePrev = null; replaceNext = null; }
// Create link without connection to the list public SDoubleLinkBase(SDoubleLinkBase <DataType> next, SDoubleLinkBase <DataType> previous) { Next = next; Previous = previous; }
// 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(SDoubleLinkBase <DataType> link, SDoubleLinkBase <DataType> replace) { Debug.Assert(link != null); Debug.Assert(replace != null); link.LinkReplace(replace); }
// Adds this element to the list, after the specified element public void LinkAfter(SDoubleLinkBase <DataType> link, SDoubleLinkBase <DataType> after) { Debug.Assert(link != null); Debug.Assert(after != null); link.LinkAfter(after); }
// Adds this element to a list, before the given element. public void LinkBefore(SDoubleLinkBase <DataType> link, SDoubleLinkBase <DataType> before) { Debug.Assert(link != null); Debug.Assert(before != null); link.LinkBefore(before); }
// Unlink @link from the list public void Unlink(SDoubleLinkBase <DataType> link) { Debug.Assert(link != null); link.Unlink(); }
public SDoubleLinkedList() { First = Last = Root; }