public void AddBefore(LinkedListNode_ <T> node, T value)
        {
            ValidateNode(node);
            LinkedListNode_ <T> newNode = new LinkedListNode_ <T>(node.list, value);

            InternalInsertNodeBefore(node, newNode);
        }
        public void AddAfter(LinkedListNode_ <T> node, T value)
        {
            ValidateNode(node);//check that node is from this linked list
            LinkedListNode_ <T> newNode = new LinkedListNode_ <T>(node.list, value);

            InternalInsertNodeBefore(node.next, newNode);
        }
 private void InternalInsertNodeToEmptyList(LinkedListNode_ <T> newNode)
 {
     Debug.Assert(head == null && count == 0, "LinkedList must be empty when this method called!");
     //newNode.next = newNode;//to circure linked link
     //newNode.prev = null;
     head = newNode;
     count++;
 }
        public IEnumerator <T> GetEnumerator()
        {
            LinkedListNode_ <T> temp = head;

            while (temp.next != null)
            {
                yield return(temp.item);

                temp = temp.next;
            }
        }
 public void addLast(LinkedListNode_ <T> node)
 {
     if (head == null)
     {
         InternalInsertNodeToEmptyList(node);
     }
     else
     {
         InternalInsertNodeBefore(Last, node);
     }
 }
        internal void ValidateNode(LinkedListNode_ <T> node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("Node");
            }

            if (node.list != this)
            {
                throw new InvalidOperationException();
            }
        }
        public LinkedListNode_ <T> Find(T item)
        {
            LinkedListNode_ <T> temp = head;

            while (temp.next != null)
            {
                if (temp.Item == temp.next.item)
                {
                    return(temp);
                }
            }
            return(null);
        }
        private void InternalInsertNodeBefore(LinkedListNode_ <T> node, LinkedListNode_ <T> newNode)
        {
            //newNode.next = node;//for circuce linked list
            //newNode.prev = head.prev;
            //newNode.prev = node;
            //node.next = newNode;


            newNode.next = node;
            newNode.prev = node.prev;
            node.prev    = newNode;
            count++;
        }
        public void addLast(T value)
        {
            LinkedListNode_ <T> newNode = new LinkedListNode_ <T>(this, value);

            if (head == null)
            {
                InternalInsertNodeToEmptyList(newNode);
            }
            else
            {
                InternalInsertNodeBefore(Last, newNode);
            }
        }
        public void Clear()
        {
            LinkedListNode_ <T> current = head;

            while (current.next != null)
            {
                LinkedListNode_ <T> temp = current;
                current = current.next;
                temp.Invalidate();
            }

            head  = null;
            count = 0;
        }
 internal void Invalidate()
 {
     list = null;
     next = null;
     prev = null;
 }