public T[] ToArray()
        {
            DoublyNode <T> current = head;

            T[] array = new T[count];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = current.Data;
                current  = current.Next;
            }
            return(array);
        }
        public void Add(T data)
        {
            DoublyNode <T> node = new DoublyNode <T>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
        public void UpdateAtIndex(T newData, int index)
        {
            if (index >= count)
            {
                throw new IndexOutOfRangeException("List does not contain an item at such index.");
            }
            if (index < 0)
            {
                throw new IndexOutOfRangeException("Index cannot be negative.");
            }
            DoublyNode <T> current = head;

            for (int i = 0; current != null; i++)
            {
                if (i == index)
                {
                    current.Data = newData;
                }
                else
                {
                    current = current.Next;
                }
            }
        }
        public T ItemAt(int index)
        {
            if (index >= count)
            {
                throw new IndexOutOfRangeException("List is smaller than the index.");
            }
            if (index < 0)
            {
                throw new IndexOutOfRangeException("Index cannot be negative.");
            }
            DoublyNode <T> current = head;

            for (int i = 0; current != null; i++)
            {
                if (i == index)
                {
                    return(current.Data);
                }
                else
                {
                    current = current.Next;
                }
            }
            return(default);
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }