Exemplo n.º 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);
 }
Exemplo n.º 2
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            AnLinkedListNode <T> node = head;

            while (node != null)
            {
                array[arrayIndex++] = node.Value;
                node = node.Next;
            }
        }
Exemplo n.º 3
0
        public IEnumerator <T> GetEnumerator()
        {
            AnLinkedListNode <T> node = head;

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

                node = node.Next;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 public bool RemoveFirst()
 {
     if (head != null)
     {
         head = head.Next;
         if (head == null)
         {
             tail = null;
         }
         Count--;
         return(true);
     }
     return(false);
 }
Exemplo n.º 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++;
        }
Exemplo n.º 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++;
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     Count = 0;
 }