Got SIGSEGV error in this function which basically swaps every two numbers
void swap(struct node *head){
if(head == NULL || head->next == NULL)
return;
struct node *temp = head,*temp1 = head->next,*ptr,*start = NULL;
while(temp1 != NULL){
temp->next = temp1->next;
temp1->next = temp;
if(start == NULL)
start = temp1;
else
ptr->next = temp1;
ptr = temp;
temp = temp->next;
temp1 = temp->next;
display(start);
}
}
Ideone link