I am trying to insert into a linked list, but when I insert two numbers and the second number is smaller than the first, I get a segmentation fault. There is an error with prev->next = newPtr, but I'm not sure why.
Like vlad said, the allocations are useless. You don't need to allocate memory if the pointer is just pointing to another node and not holding any data. All you need to traverse the list is two pointers: