Пример #1
0
 public bool RemoveLast()
 {
     if (head != null)
     {
         AnLinkedListNode <T> node     = head;
         AnLinkedListNode <T> previous = null;
         while (node != null)
         {
             if (node.Next == null)
             {
                 if (previous == null)
                 {
                     head = null;
                     tail = null;
                 }
                 else
                 {
                     previous.Next = null;
                     tail          = previous;
                 }
                 Count--;
                 return(true);
             }
             previous = node;
             node     = node.Next;
         }
     }
     return(false);
 }
Пример #2
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            AnLinkedListNode <T> node = head;

            while (node != null)
            {
                array[arrayIndex++] = node.Value;
                node = node.Next;
            }
        }
Пример #3
0
        public IEnumerator <T> GetEnumerator()
        {
            AnLinkedListNode <T> node = head;

            while (node != null)
            {
                yield return(node.Value);

                node = node.Next;
            }
        }
Пример #4
0
        public bool Contains(T item)
        {
            AnLinkedListNode <T> node = head;

            while (node != null)
            {
                if (node.Value.Equals(item))
                {
                    return(true);
                }
                node = node.Next;
            }
            return(false);
        }
Пример #5
0
 public bool RemoveFirst()
 {
     if (head != null)
     {
         head = head.Next;
         if (head == null)
         {
             tail = null;
         }
         Count--;
         return(true);
     }
     return(false);
 }
Пример #6
0
        public void AddLast(T item)
        {
            AnLinkedListNode <T> node = new AnLinkedListNode <T>(item);

            if (head == null) //empty list
            {
                head = node;
            }
            else
            {
                tail.Next = node;
            }

            tail = node;
            Count++;
        }
Пример #7
0
        public void AddFirst(T item)
        {
            AnLinkedListNode <T> node = new AnLinkedListNode <T>(item);

            if (head == null)
            {
                //head = node;
                tail = node;
            }
            else
            {
                node.Next = head;
                //head = node;
            }
            head = node;
            Count++;
        }
Пример #8
0
        public bool Remove(T item)
        {
            AnLinkedListNode <T> node     = head;
            AnLinkedListNode <T> previous = null;

            while (node != null)
            {
                if (node.Value.Equals(item))
                {
                    if (previous == null)//first list element
                    {
                        head = null;
                        tail = null;
                    }
                    else
                    {
                        if (node.Next == null) //last list element
                        {
                            previous.Next = null;
                            tail          = previous;
                        }
                        else //middle.. list element
                        {
                            previous.Next = node.Next;
                        }
                    }

                    Count--;
                    return(true);
                }
                //else
                previous = node;
                node     = node.Next;
            }
            return(false);
        }
Пример #9
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     Count = 0;
 }