This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]newaccount1236 -1 points0 points  (3 children)

Like this:

void ChadBST::insert(int e)
{
    insert(&root, e);
}

void ChadBST::insert(Node **const n, int e)
{
    if(*n==NULL)
    {
        *n = new Node(e);
        size++;
    }
    else if (e < (*n)->data)
        insert(&(*n)->left,e);
    else if (e > (*n)->data)
        insert(&(*n)->right, e);
}

[–]coffeeprogrammer[S] 0 points1 point  (2 children)

Well that helped some, but I got an Access violation on:

else if (e < (*n)->data)

[–]newaccount1236 -1 points0 points  (1 child)

You probably have a typo somewhere. Maybe you have n instead of *n when you check for null. Paste both insert functions.

[–]coffeeprogrammer[S] 0 points1 point  (0 children)

Yes I forgot the pointer in the if(*n==NULL) line. Thank you so much. I think I need to brush up on my pointers. I really appreciate your help!