I have the following code ( I'm creating a binary tree and then I want to print the values on it's leafs) but when I'm running it, it never enters in that if from the parcurgere function. What have I done wrong?
#include <iostream>
using namespace std;
class node
{
public: int val;
static int niv;
node *st;
node *dr;
node(int i)
{
val = i;
st = NULL;
dr = NULL;
}
};
void creare(node *p)
{
int x;
cin>>x;
if(x == 0)
{
p = NULL;
}
else
{
node *p = new node(x);
cout<<"dati fiul stang al lui "<<x<<" ";
creare(p->st);
cout<<"dati fiul drept al lui "<<x<<" ";
creare(p->dr);
}
}
void parcurgere(node *p)
{
if(p != NULL)
{
cout<<p->val;
parcurgere(p->st);
parcurgere(p->dr);
}
}
void main()
{
node *t = NULL;
cout<<"dati radacina arborelui ";
creare(t);
parcurgere(t);
}