So I'm quite familiar with java, but need to bring myself up to speed on c++. I've got this code going, very basic, just starting some basic functions. My question is as to why the two argument insert doesn't update the pointer in the one argument insert. (to the root, specifically)
Code:
Any input is appreciated,Code:#include <iostream> using namespace std; struct node { int keyVal; node * left; node * right; }; class BinarySearchTree { public: BinarySearchTree(); ~BinarySearchTree(); void insert(int key); private: node * root; void insert(int key, node * node); }; BinarySearchTree::BinarySearchTree() { root = NULL; } BinarySearchTree::~BinarySearchTree() { } void BinarySearchTree::insert(int key) { insert(key, root); if (root == NULL) { cout << "Didn't work."; } } void BinarySearchTree::insert(int key, node * leaf) { if (leaf == NULL) { leaf = new node; leaf->keyVal = key; leaf->left = NULL; leaf->right = NULL; } } int main() { BinarySearchTree foo; foo.insert(14); }
thanks.



LinkBack URL
About LinkBacks



