I want to create the root pointer in my program not in the class
bst.h
--BSTtree class (no pointers)?
bst.cpp
bstprog.cpp
&&&&&&&
what does this line do/mean
typedef treeNode *treeNodePtr;
I want to create the root pointer in my program not in the class
bst.h
--BSTtree class (no pointers)?
bst.cpp
bstprog.cpp
&&&&&&&
what does this line do/mean
typedef treeNode *treeNodePtr;
trees generally use pointers to nodes rather than nodes as such. the root node is therefore better defined as a pointer to a given node, not a node as such. This enables you to pass the entry point for the data stored in the tree from function to function much easier. if your bst is a templated class then root would be set to null in the header file by the constructor. If the bst class is not templated then you would set root to null in constructor definition in the cpp file for the bst class. to insert data you create a new node using dynamic memory, ie create a pointer to a new node declared in dynamic memory. If the bst is empty you assign the new node to the root node, and if not you find the spot to insert the new node by searching the tree.
typedef treeNode *treeNodePtr;
this means that whenever you write treeNodePtr you mean treeNode *;
like this:
treeNodePtr currentNode;
instead of like this:
treeNode * currentNode;
>I want to create the root pointer in my program not in the class
Why? If you're using a class then theoretically you should be hiding the internal mechanisms of the tree from client code. Therefore, the tree class would control the root pointer.
>--BSTtree class (no pointers)?
While you can implement a binary search tree without pointers, you really don't want to. Take my word for it.
>typedef treeNode *treeNodePtr;
It creates a synonym for treeNode*. Every variable you declare as treeNodePtr will really be treeNode*.
My best code is written with the delete key.