I'm trying to get the Nodes with negative integer from a Linked List and create a new Linked list for them. However, at the last if statement, I try to set the next of the last item to null, but it gives a runtime error. The error is "Process returned -1073741819 (0xC0000005)"
Node* selectNeg(Node* head)
{
Node *result=NULL;
Node *cur=head;
Node *lastly;
while(cur!=NULL)
{
if(cur->item<0)
{
Node *temp=new Node;
temp->item=cur->item;
if(result==NULL)
{
result=temp;
}
else
{
lastly->next=temp;
lastly=temp;
}
}
cur=cur->next;
}
if(result!=NULL)
{
lastly->next=NULL;
}
return result;
}
User contributions licensed under CC BY-SA 3.0