how to define a node in class node in the linked list

-1

i'm trying to define the node in the node class but it gaves me this error on VS Unhandled exception at 0x77477268 (ntdll.dll) in q3.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00C02FFC). occurred

class node
{
public:
    node()
    {
        data = 0;
        next = NULL;
    }

    int data;
    node *next = new node();
};

and when I run this function it gives me this error Unhandled exception thrown: read access violation. cur was nullptr. occurred

void list::input(int x)
{
    node *cur = new node();
    node *pr = new node();
    node *temp = new node();
    temp->data = x;
    cur = head;

    if (head == nullptr)
    {
        head = temp;
    }
    else if (x<head->data)
        {
            temp->next = head;
            head = temp;
        }

    else
    {
        while (x > cur->data && cur != nullptr)
        {
            pr = cur;
            cur = cur->next;
        }
        pr->next = temp;
        temp->next = cur;


    }

}
c++
class
pointers
singly-linked-list
asked on Stack Overflow Nov 2, 2019 by Eyad Azzam • edited Nov 3, 2019 by Eyad Azzam

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0