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;
}
}
User contributions licensed under CC BY-SA 3.0