public void AddFirst(CustomLinkedListNode <T> node)
 {
     Head.Previous = node;
     node.Next     = Head;
     Head          = node;
     Count++;
 }
 public void AddLast(CustomLinkedListNode <T> node)
 {
     Tail.Next     = node;
     node.Previous = Tail;
     Tail          = node;
     Count++;
 }
        public void Insert(int index, T value)
        {
            var newNode = new CustomLinkedListNode <T>(value);
            var current = Head;
            int counter = 0;

            if (!ReferenceEquals(Head, current))
            {
                while (counter < index)
                {
                    current = current.Next;
                    counter++;
                }

                current.Previous.Next = newNode;
                newNode.Next          = current;
                newNode.Previous      = current.Previous;
                current.Previous      = newNode;
                Count++;
            }
            else
            {
                current.Previous = newNode;
                newNode.Next     = current;
                Head             = newNode;
                Count++;
            }
        }
        private void Initialize(T value)
        {
            var item = new CustomLinkedListNode <T>(value);

            Head  = item;
            Tail  = item;
            Count = 1;
        }
 public void AddBefore(CustomLinkedListNode <T> node, CustomLinkedListNode <T> newNode)
 {
     node.Previous.Next = newNode;
     newNode.Previous   = node.Previous;
     newNode.Next       = node;
     node.Previous      = newNode;
     Count++;
 }
 public void AddAfter(CustomLinkedListNode <T> node, CustomLinkedListNode <T> newNode)
 {
     node.Next.Previous = newNode;
     newNode.Next       = node.Next;
     newNode.Previous   = node;
     node.Next          = newNode;
     Count++;
 }
        public CustomLinkedListNode <T> AddAfter(CustomLinkedListNode <T> node, T value)
        {
            var newNode = new CustomLinkedListNode <T>(value);

            node.Next.Previous = newNode;
            newNode.Next       = node.Next;
            newNode.Previous   = node;
            node.Next          = newNode;
            Count++;
            return(newNode);
        }
        public CustomLinkedListNode <T> AddBefore(CustomLinkedListNode <T> node, T value)
        {
            var newNode = new CustomLinkedListNode <T>(value)
            {
                Previous = node.Previous
            };

            node.Previous.Next = newNode;
            newNode.Next       = node;
            node.Previous      = newNode;
            Count++;

            return(newNode);
        }
 public void Add(T data)
 {
     if (Tail != null)
     {
         var item = new CustomLinkedListNode <T>(data);
         Tail.Next     = item;
         item.Previous = Tail;
         Tail          = item;
         Count++;
     }
     else
     {
         Initialize(data);
     }
 }
        public void Remove(CustomLinkedListNode <T> node)
        {
            if (ReferenceEquals(node, Head))
            {
                RemoveFirst();
                return;
            }

            if (ReferenceEquals(node, Tail))
            {
                RemoveLast();
                return;
            }

            node.Previous.Next = node.Next;
            node.Next.Previous = node.Previous;
            node.Next          = null;
            node.Previous      = null;
            Count--;
        }