Пример #1
0
 public bool MoveNext()
 {
     if (CurrentNode == null)
     {
         CurrentNode = Head;
         return(true);
     }
     else if (Head.Element != null && Head.NextElement != null)
     {
         Head = (TwoLinkedNode <T>)Head.NextElement;
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public override void Delete(T value)
        {
            TwoLinkedNode <T> previousfirst = null;
            TwoLinkedNode <T> first         = (TwoLinkedNode <T>)Head;
            TwoLinkedNode <T> last          = (TwoLinkedNode <T>)Tail;
            TwoLinkedNode <T> previouslast  = null;

            while (first != null || last != null)
            {
                if (first.Element.Equals(value))
                {
                    if (previousfirst != null)
                    {
                        previousfirst.NextElement = first.NextElement;
                        last = first;
                        last.PreviousElement = (TwoLinkedNode <T>)last.NextElement;
                        {
                            if (first.NextElement == null)
                            {
                                Tail = first;
                            }
                        }
                        return;
                    }
                    else
                    {
                        Head = (TwoLinkedNode <T>)Head.NextElement;
                        ((TwoLinkedNode <T>)Head).PreviousElement = (((TwoLinkedNode <T>)Head).PreviousElement).PreviousElement;
                        if (Head == null)
                        {
                            Tail = null;
                        }
                        return;
                    }
                }
                if (last.Element.Equals(value))
                {
                    if (previouslast != null)
                    {
                        previouslast.PreviousElement = last.PreviousElement;
                        first = last;
                        first.PreviousElement = (TwoLinkedNode <T>)first.NextElement;
                        {
                            if (last.PreviousElement == null)
                            {
                                Tail = previouslast;
                            }
                        }
                        return;
                    }
                    else
                    {
                        Tail = ((TwoLinkedNode <T>)Tail).PreviousElement;
                        ((TwoLinkedNode <T>)Tail).NextElement = Tail.NextElement.NextElement;
                        if (Tail == null)
                        {
                            Head = null;
                        }
                        return;
                    }
                }
                previouslast  = last;
                last          = last.PreviousElement;
                previousfirst = first;
                first         = (TwoLinkedNode <T>)first.NextElement;
            }
        }
Пример #3
0
 public void Reset()
 {
     Head = null;
 }
Пример #4
0
 public TwoLinkedCustomListEnumerator(TwoLinkedNode <T> head)
 {
     Head        = head;
     CurrentNode = null;
 }