I can't add nodes like in a binary search tree. It seems the add function is the problem because it don't actually change the root node or any other nodes. What can I do?
#include <iostream>
#include <string.h>
using namespace std;
typedef struct Node{
int data;
Node* left=NULL;
Node* right=NULL;
}Node;
Node* root=NULL;
void add(Node* r, Node* node){
if(r==NULL){
r=node;
return;
}
if(r->data > node->data){
add(r->left, node);
return;
}
add(r-> right, node);
}
int main() {
Node* r=new Node;
r->data=5;
add(root,r);
cout<<root->data;
return 0;
}