I m writing a function to insert a number in a sorted linked list in C++. However, I am getting "Segmentation Fault" when I run it. Can anyone explain why it is so?
    Node * insertInSorted(Node * head, int data)
{
    Node * curr = head;
    Node * a = new Node(data);
    
    while(curr->next->data < a->data || curr->next != NULL)
    {
        curr = curr->next;
    }
    
    Node * temp = curr->next;
    
    curr->next = a;
    a->next = temp;
    
    return head;
}
 
    