Ejemplo n.º 1
0
        // ====================================================================================
        // Interfaces
        // ====================================================================================

        #region IComparable
        public int CompareTo(DoubleLink <T> other)
        {
            if (other == null)
            {
                return(-1);
            }
            return(Data.CompareTo(other.Data));
        }
Ejemplo n.º 2
0
 // Add last element
 public void AddFirst(DoubleLink <T> link)
 {
     Debug.Assert(link != null);
     if (link.IsLinked)
     {
         link.Unlink();
     }
     link.LinkBefore(First);
 }
Ejemplo n.º 3
0
 // Add first element
 public void AddLast(DoubleLink <T> link)
 {
     Debug.Assert(link != null);
     if (link.IsLinked)
     {
         link.Unlink();
     }
     link.LinkAfter(Last);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 12
0
 // Unlink @link from the list
 public void Unlink(DoubleLink <T> link)
 {
     Debug.Assert(link != null);
     link.Unlink();
 }
Ejemplo n.º 13
0
 public DoubleLinkedList()
 {
     First = Last = Root;
 }