Ejemplo n.º 1
0
 public void Remove()
 {
     this.myEnumerator.SetInvalid();
     if (null != this.cursor)
     {
         DLNode <T> old = this.cursor;
         if (this.cursor == this.head)
         {
             this.head = this.cursor.Next;
         }
         if (this.cursor == this.tail)
         {
             this.tail = this.cursor.Prev;
         }
         if (null != this.cursor.Next)
         {
             this.cursor.Next.Prev = this.cursor.Prev;
         }
         if (null != this.cursor.Prev)
         {
             this.cursor.Prev.Next = this.cursor.Next;
         }
         if (null != this.cursor.Next)
         {
             this.cursor = this.cursor.Next;
         }
         else
         {
             this.cursor = this.cursor.Prev;
         }
         Delete(old);
     }
 }
Ejemplo n.º 2
0
        public void AddAfter(T item)
        {
            this.myEnumerator.SetInvalid();
            DLNode <T> node = New(item);

            if (null == this.tail)
            {
                this.tail   = node;
                this.head   = node;
                this.cursor = node;
            }
            else if (this.cursor == this.tail)     // neither tail nor cursor are null
            {
                this.tail      = node;
                node.Prev      = this.cursor;
                node.Prev.Next = node;
                this.cursor    = node; // we set the cursor ti the inserted node
            }
            else
            {
                node.Next      = this.cursor.Next;
                node.Prev      = this.cursor;
                node.Next.Prev = node;
                node.Prev.Next = node;
                this.cursor    = node; // we set the cursor to the inserted node
            }
        }
Ejemplo n.º 3
0
 public bool MoveNext()
 {
     if (null == this.current)
     {
         this.current = this.root;
     }
     else
     {
         this.current = this.current.Next;
     }
     return(null != this.current);
 }
Ejemplo n.º 4
0
 public void MoveCursorPrev()
 {
     if (null != this.cursor)
     {
         if (null != this.cursor.Prev)
         {
             this.cursor = this.cursor.Prev;
         }
     }
     else
     {
         cursor = this.head;
     }
 }
Ejemplo n.º 5
0
 public void MoveCursorNext()
 {
     if (null != this.cursor)
     {
         if (null != this.cursor.Next)
         {
             this.cursor = this.cursor.Next;
         }
     }
     else
     {
         cursor = this.tail;
     }
 }
Ejemplo n.º 6
0
        private static void freeMemory()
        {
            DLNode <T> current = avail;
            DLNode <T> next    = avail;

            while (null != current)
            {
                next         = current.Next;
                current.Item = null;
                current.Prev = null;
                current.Next = null;
                current      = next;
            }
            avail = null;
        }
Ejemplo n.º 7
0
        private static DLNode <T> New(T item)
        {
            DLNode <T> result = null;

            if (null != avail)
            {
                result      = avail;
                avail       = avail.Next;
                result.Prev = null;
                result.Next = null;
                result.Item = item;
            }
            else
            {
                result = new DLNode <T>(item);
            }
            return(result);
        }
Ejemplo n.º 8
0
 public void SetValid(DLNode <M> start)
 {
     this.root = start;
 }
Ejemplo n.º 9
0
 private static void Delete(DLNode <T> node)
 {
     node.Item = null;  node.Next = avail; avail = node;
 }