Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

SIGSEGV error in linked-list swapping

$
0
0

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


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>