27 #define BST_MALLOC_ERROR -1 34 template<
class BST_TYPE>
41 typedef int(BST_TYPE::*BSTCompareMethod)(
const BST_TYPE&)
const;
56 if (childL)
delete childL;
58 if (childR)
delete childR;
60 if (value)
delete value;
70 int add(BST_TYPE *v, BSTCompareMethod compare=NULL){
78 comparison=(*value.*compare)(*v);
80 comparison=(*v>*value);
88 cerr<<
"couldn't create new BST child"<<endl;
92 return (*child)->add(v, compare);
106 if ((res=add(linkList->
remove(), compare))<0)
108 removeSorted(linkList);
118 delete childL; childL=NULL;
121 linkList->
add(value);
126 delete childR; childR=NULL;
BST_TYPE * value
The pointer to the variable.
int add(BST_TYPE *v, BSTCompareMethod compare=NULL)
BST(BST_TYPE *v=NULL, BST *cL=NULL, BST *cR=NULL)
TYPE remove(void)
remove the current lug from the LinkList The current lug is removed form the list and passed back to ...
BST * childR
Left and right children nodes.
void add(TYPE newElement)
Adds as the current element ... Added to the next of the current lug.
void removeSorted(LinkList< BST_TYPE *> *linkList)
~BST(void)
Destructor - any resident variable or children are deleted.
int sort(LinkList< BST_TYPE *> *linkList, BSTCompareMethod compare=NULL)