I have three functions to managa a binary tree :
static void insertion(Noeud* &top, Noeud *newNoeud)
{
if(top == NULL)
top = newNoeud;
else if(newNoeud->nbr < top->nbr)
insertion(top->left, newNoeud);
else
insertion(top->right, newNoeud);
}
static void affichage(Noeud* &top) //displaying
{
if(top != NULL)
{
affichage(top->left);
affichage(top->right);
cout << "\n" << top->nbr;
}
}
static Noeud* recherche(Noeud* &top, int nbr) //searching
{
while(top != NULL)
{
if(top->nbr == nbr)
return(top);
else if(nbr < top->nbr)
top = top->left;
else
top = top->right;
}
}
however I keep getting an error saying that I am violating the access when trying to read a memory spot. I am guessing this has to do with my pointers but I can't guess what it is.
static Noeud* recherche(Noeud* &top, int nbr)means what it means in C++, you're passingtopby reference,top = top->left;resp.top = top->right;will destroy your tree.