Runtime Error when trying to reach next of a Node

0

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;
}
c++
runtime
asked on Stack Overflow Apr 15, 2016 by codemonkey • edited Jun 6, 2018 by codemonkey

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0