You are viewing a single comment's thread. Return to all comments →
Urgent help needed. My code is constantly showing segmentation fault. Please help. Here is code:
SinglyLinkedListNode* insertNodeAtTail(SinglyLinkedListNode* head, int data) {
SinglyLinkedListNode* temp; temp=head; SinglyLinkedListNode* new_node = (SinglyLinkedListNode*)malloc(sizeof (SinglyLinkedListNode));
if(head==NULL) { new_node->data=data; new_node->next=NULL; head=new_node; return head; }
else {
while(temp!=NULL) {temp=temp->next;}
temp->next=new_node;
new_node->next=NULL; new_node->data=data;
temp=head;
while(temp!=NULL) { printf("%d/n",temp->data); temp=temp->next; }
} return head;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a Node at the Tail of a Linked List
You are viewing a single comment's thread. Return to all comments →
Urgent help needed. My code is constantly showing segmentation fault. Please help. Here is code:
SinglyLinkedListNode* insertNodeAtTail(SinglyLinkedListNode* head, int data) {
SinglyLinkedListNode* temp; temp=head; SinglyLinkedListNode* new_node = (SinglyLinkedListNode*)malloc(sizeof (SinglyLinkedListNode));
if(head==NULL) { new_node->data=data; new_node->next=NULL; head=new_node; return head; }
else {
while(temp!=NULL) {temp=temp->next;}
temp->next=new_node;
new_node->next=NULL; new_node->data=data;
temp=head;
while(temp!=NULL) { printf("%d/n",temp->data); temp=temp->next; }
} return head;
}