I am having trouble with the following code. I am a java developer trying to teach myself c++. Mainly my code in main() is not inserting anything to the root Node. Can anyone help me. I am sure there is something off with my pointers.
class Node{
public:
Node* left;
Node* right;
int data;
Node(int n){
data = n;
right = NULL;
left = NULL;
}
};
class BST{
Node* root;
public:
BST(){
root = NULL;
}
void insert(int e){
pinsert(root, e);
}
void pinsert(Node* sr, int e){
if(sr == NULL){
sr = new Node(e);
}
else{
if((sr->data) > e ){
pinsert(sr->left, e);
}
else{
pinsert(sr->right, e);
}
}
}
};
int main(){
BST tree;
tree.insert(6);
tree.insert(7);
}
s/much/at all...).