Example #1
0
        // ====================================================================================
        // Interfaces
        // ====================================================================================

        #region IComparable
        public int CompareTo(DoubleLink <T> other)
        {
            if (other == null)
            {
                return(-1);
            }
            return(Data.CompareTo(other.Data));
        }
Example #2
0
 // Add last element
 public void AddFirst(DoubleLink <T> link)
 {
     Debug.Assert(link != null);
     if (link.IsLinked)
     {
         link.Unlink();
     }
     link.LinkBefore(First);
 }
Example #3
0
 // Add first element
 public void AddLast(DoubleLink <T> link)
 {
     Debug.Assert(link != null);
     if (link.IsLinked)
     {
         link.Unlink();
     }
     link.LinkAfter(Last);
 }
Example #4
0
 // Adds @link element to the list, with replacing the specified element.
 // This is equivalent to calling the sequence: LinkBefore(Replace); replace.Unlink();
 public void LinkReplace(DoubleLink <T> link, DoubleLink <T> replace)
 {
     Debug.Assert(link != null);
     Debug.Assert(replace != null);
     if (link == replace)
     {
         return;
     }
     link.LinkReplace(replace);
 }
Example #5
0
        // Adds this element to a list, before the given element.
        public void LinkBefore(DoubleLink <T> before)
        {
            Debug.Assert(before != null);

            Previous        = before.Previous;
            before.Previous = this;
            Next            = before;
            if (Previous != null)
            {
                Previous.Next = this;
            }
        }
Example #6
0
        // ====================================================================================
        // Methods
        // ====================================================================================

        // Remove link from list
        public void Unlink()
        {
            if (Next != null)
            {
                Next.Previous = Previous;
            }
            if (Previous != null)
            {
                Previous.Next = Next;
            }
            Next = Previous = null;
        }
Example #7
0
        // Adds this element to the list, after the specified element
        public void LinkAfter(DoubleLink <T> after)
        {
            Debug.Assert(after != null);

            Next       = after.Next;
            after.Next = this;
            Previous   = after;
            if (Next != null)
            {
                Next.Previous = this;
            }
        }
Example #8
0
        // 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(DoubleLink <T> 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;
        }
Example #9
0
 // Create link without connection to the list
 public DoubleLink(T data, DoubleLink <T> next, DoubleLink <T> previous)
 {
     Data     = data;
     Next     = next;
     Previous = previous;
 }
Example #10
0
 // Adds this element to the list, after the specified element
 public void LinkAfter(DoubleLink <T> link, DoubleLink <T> after)
 {
     Debug.Assert(link != null);
     Debug.Assert(after != null);
     link.LinkAfter(after);
 }
Example #11
0
 // Adds this element to a list, before the given element.
 public void LinkBefore(DoubleLink <T> link, DoubleLink <T> before)
 {
     Debug.Assert(link != null);
     Debug.Assert(before != null);
     link.LinkBefore(before);
 }
Example #12
0
 // Unlink @link from the list
 public void Unlink(DoubleLink <T> link)
 {
     Debug.Assert(link != null);
     link.Unlink();
 }
Example #13
0
 public DoubleLinkedList()
 {
     First = Last = Root;
 }