Hey All - i working on a assignment for school. Given that, i would like to say i have attempted numerous ways to get this working, and its a simple part of teh assignment. Basically i am having problems with my 'insert node' method. I am unsure how i have to declare the new node... example of my problem below:
BSTNode<T> * newNode;
newNode->data = newitem; (new item is the informaiton passed to the Insert method)
My class for a node is as follows:
template <class T>
class BSTNode
{
friend class BSTree<T>;
private:
T data;
BSTNode<T>* left;
BSTNode<T>* right;
public:
BSTNode(const T&);
};
So i should be able to make a call to the constructor passing in the newitem argument as the data member... my constructor looks like:
template <class T>
BSTNode<T>::BSTNode(const T& item)
{
data = item;
left = right = NULL;
}
I was trying things such as:
BSTNode<T>(newItem);
But, as you can probably tell, i dont have a way to reference this new node that would be created, plus its not a pointer - so i wont have access via nodeName->data; right?
Sorry if this seems slow, or very easy ... but this is brand new to me, and im just trying to get my mind around it.
PS. I know the code for the insert is pretty much correct, as this was taken from in class notes from my professor, (i had to add code where he basically told us ... you need a to do b in this part, and c to do d in this area etc etc)
Hope this makes sense to someone!
Thank you in advance