Code:#include<iostream> #include<string> using namespace std; class node { private: int data; node *left; node *right; public: node(int d) { data=d; cout<<data<<endl; left=NULL; right=NULL; } friend class list; }; class list { public: node *root; node *newnode; list() { root=NULL; } void insert(node *r, int data) { if(r==NULL) { r=new node(data); } else if(data>r->data) { insert(r->right,data); } else if(data<r->data) { insert(r->left,data); } } /*void insert(node *nd,int data) { if(nd==NULL) { nd=new node(data); } else if(data>nd->data) { insert(nd->right,data); } else if(data<nd->data) { insert(nd->left,data); } }*/ void display(node *temp) { cout<<"sdff"<<endl; cout<<temp->data; if(temp) { cout<<"dsfs"<<temp->data<<endl; display(temp->left); display(temp->right); } } void display() { if(root) { cout<<root->data<<endl; display(root->right); display(root->left); } } }; int main() { list l; l.insert(l.root,9); l.insert(l.root,6); l.insert(l.root,10); l.display(l.root); }
what is wrong with my code??