I am working on trying to split my doubly linked list. But i get nullpointer exception on sublist.head = mid.next. Does it means sublist.head is pointing to null? How can i resolve this??
public void splitMid(DoublyLinkedList<T> sublist)
{
    Node<T> current;
    Node<T> mid;
    int i;
    if (head == null)
    {
        sublist.head = null;
        sublist.rear = null;
        sublist.count = 0;
    }
    else
        if (head.next == null)
        {
            sublist.head = null;
            sublist.rear = null;
            sublist.count = 0;
        }
        else
        {
            mid = head;
            current = head.next;
            i = 1;
            if (current != null)
                current = current.next;
            while (current != null)
            {
                mid = mid.next;
                current = current.next;
                i++;
                if (current != null)
                    current = current.next;
            }
            sublist.head = mid.next;
            sublist.rear = rear;
            rear = mid;
            rear.next = null;
            sublist.count = count - i;
            count = i;
        }
}
 
    