Пример #1
0
 // Add first element
 public void AddLast(SDoubleLinkBase <DataType> link)
 {
     Debug.Assert(link != null);
     if (link.IsLinked)
     {
         link.Unlink();
     }
     link.LinkAfter(Last);
 }
Пример #2
0
 // Add last element
 public void AddFirst(SDoubleLinkBase <DataType> link)
 {
     Debug.Assert(link != null);
     if (link.IsLinked)
     {
         link.Unlink();
     }
     link.LinkBefore(First);
 }
Пример #3
0
        // 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;
            }
        }
Пример #4
0
        // 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;
            }
        }
Пример #5
0
        // ====================================================================================
        // Methods
        // ====================================================================================

        // Remove link from list
        public void Unlink()
        {
            if (Next != null)
            {
                Next.Previous = Previous;
            }
            if (Previous != null)
            {
                Previous.Next = Next;
            }
            Next = Previous = null;
        }
Пример #6
0
        // ====================================================================================
        // Interfaces
        // ====================================================================================

        #region IComparable
        public int CompareTo(SDoubleLinkBase <DataType> other)
        {
            if (other == null)
            {
                return(-1);
            }
            if (other != this)
            {
                return(-1);
            }
            return(CompareTo(other));
        }
Пример #7
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(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;
        }
Пример #8
0
 // Create link without connection to the list
 public SDoubleLinkBase(SDoubleLinkBase <DataType> next, SDoubleLinkBase <DataType> previous)
 {
     Next     = next;
     Previous = previous;
 }
Пример #9
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(SDoubleLinkBase <DataType> link, SDoubleLinkBase <DataType> replace)
 {
     Debug.Assert(link != null);
     Debug.Assert(replace != null);
     link.LinkReplace(replace);
 }
Пример #10
0
 // 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);
 }
Пример #11
0
 // 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);
 }
Пример #12
0
 // Unlink @link from the list
 public void Unlink(SDoubleLinkBase <DataType> link)
 {
     Debug.Assert(link != null);
     link.Unlink();
 }
Пример #13
0
 public SDoubleLinkedList()
 {
     First = Last = Root;
 }