So I have an assignment where I\'m giving a random list of number and I need to sort them using insertion sort. I must use a singly linked list. I looked around at other posts b
Think about this - if the list is empty, temp will initially be NULL, so you get undefined behavior when you do temp->next = head;.
Try some debugging, it will surely help. You'll probably either want to keep the previous node as well, so you can insert afterwards, or look 2 nodes forward.