58 if (this->
_parent->_left ==
this)
return -1;
59 else if (this->
_parent->_right ==
this)
return 1;
96 if (gp->_left == this->
_parent)
return gp->_right;
97 else return gp->_left;
118 if (this->_left && this->_right) {
120 }
else if (this->_left || this->_right) {
131 int lvl = this->
level();
133 for (
int i = 1; i <= lvl; i++) {
135 if (!this->
isRoot()) std::cout <<
" |";
139 if (this->
childType() != 0) std::cout <<
" |";
140 else std::cout <<
" ";
146 std::cout <<
"[" << this->
_obj <<
"]" << std::endl;
165 this->_right =
right;
227 int result = this->
_st.pop();
249 int result = this->
_st.push(node);
251 if (!result && node->
left())
267 this->_compare = NULL;
321 std::cout << std::endl;
323 std::cout << std::endl;
329 return node ? node->
_obj : 0;
335 return node ? node->
_obj : 0;
375 if (result == 0) this->_root = NULL;
386 int result = this->locateLeafNodes(&leafNodes, this->
root());
392 }
while ((listNode = listNode->
next()));
411 result = (*itr)->setCurrent(this->
root());
439 if (this->_compare)
return this->_compare(a, b);
441 if (a == b)
return 0;
442 else if (a < b)
return -1;
443 else if (a > b)
return 1;
459 if (!node)
return NULL;
464 }
else if (cmp > 0) {
511 if (!newNode)
return 1;
512 else if (!parent)
return 2;
516 newLocation = &parent->_right;
518 newLocation = &parent->_left;
528 *newLocation = newNode;
544 return *newLocation == NULL;
564 }
else if (node->
right()) {
641 unsigned char childCount = 0;
650 if (childCount == 0) {
653 }
else if (childCount == 1) {
676 if (node->
left() != repNode) {
681 if (node->
right() != repNode) {
708 if (!node)
return NULL;
715 if (!node)
return NULL;
752 virtual int locateLeafNodes(List<const BinNode *> * outList,
const BinNode * node) {
756 else if (node->childCount() > 0) {
757 if (node->left()) result = this->locateLeafNodes(outList, node->left());
760 if (node->right()) result = this->locateLeafNodes(outList, node->right());
764 result = outList->add(node);
774 int (* _compare) (T a1, T a2);
Definition bintree.hpp:26
T _obj
Definition bintree.hpp:187
virtual void setLeft(BinNode *left)
Definition bintree.hpp:155
int level() const
Definition bintree.hpp:126
virtual BinNode * right()
Definition bintree.hpp:175
virtual const BinNode * left() const
Definition bintree.hpp:33
virtual unsigned char childCount() const
Definition bintree.hpp:117
virtual ~BinNode()
Definition bintree.hpp:77
char childType() const
Definition bintree.hpp:55
BinNode(T object)
Definition bintree.hpp:73
BinNode()
Definition bintree.hpp:65
virtual bool isLeaf() const
Definition bintree.hpp:38
virtual BinNode * sibling()
Definition bintree.hpp:104
BinNode ** leftAddr()
Definition bintree.hpp:173
const BinNode * parent() const
Definition bintree.hpp:35
virtual BinNode * clone()
Definition bintree.hpp:150
T object() const
Definition bintree.hpp:29
BinNode ** _location
Definition bintree.hpp:184
virtual BinNode * grandParent()
Definition bintree.hpp:86
bool isRoot() const
Definition bintree.hpp:43
virtual BinNode * left()
Definition bintree.hpp:172
virtual BinNode * pibling()
Definition bintree.hpp:92
virtual const BinNode * right() const
Definition bintree.hpp:34
BinNode * _parent
Definition bintree.hpp:179
BinNode ** rightAddr()
Definition bintree.hpp:176
virtual void setRight(BinNode *right)
Definition bintree.hpp:164
virtual void print() const
Definition bintree.hpp:130
Definition bintree.hpp:207
bool finished()
Definition bintree.hpp:239
Iterator()
Definition bintree.hpp:257
virtual int setCurrent(BinNode *node)
Definition bintree.hpp:246
virtual ~Iterator()
Definition bintree.hpp:211
Stack< BinNode * > _st
Definition bintree.hpp:262
T current()
Definition bintree.hpp:218
int next()
Definition bintree.hpp:225
Definition bintree.hpp:23
int insert(T obj)
Definition bintree.hpp:292
BinNode * getNodeParent(const BinNode *node)
Definition bintree.hpp:497
virtual ~BinTree()
Definition bintree.hpp:271
virtual const BinNode * minNode() const
Definition bintree.hpp:338
T max() const
Definition bintree.hpp:327
BinNode ** rootAddr()
Root accessors.
Definition bintree.hpp:473
virtual int insert(BinNode *newNode, BinNode *parent)
Definition bintree.hpp:508
virtual void * createNode()
Definition bintree.hpp:490
virtual int deleteNode(BinNode *node)
Definition bintree.hpp:358
BinTree()
Definition bintree.hpp:265
void setNodeParent(BinNode *node, BinNode *parent)
Definition bintree.hpp:498
virtual BinNode * root()
Definition bintree.hpp:477
virtual void print(BinNode *node)
Definition bintree.hpp:698
T min() const
Definition bintree.hpp:333
void setNodeLocation(BinNode *node, BinNode **location)
Definition bintree.hpp:495
bool contains(T obj)
Definition bintree.hpp:311
virtual bool canNewNodeTakeNewLocation(BinNode **newLocation)
Definition bintree.hpp:543
virtual const BinNode * maxNode(const BinNode *node) const
Returns the leaf node
Definition bintree.hpp:707
void setRoot(BinNode *node)
Definition bintree.hpp:474
virtual int remove(T obj)
Definition bintree.hpp:349
BinNode * getNodeForObject(T obj, BinNode *node)
Definition bintree.hpp:458
int runCompare(T a, T b) const
Definition bintree.hpp:438
S count() const
Definition bintree.hpp:306
S _count
Definition bintree.hpp:482
virtual void print()
Definition bintree.hpp:320
int removeNode(BinNode *node)
Definition bintree.hpp:639
virtual const BinNode * getNodeForObject(T obj)
Definition bintree.hpp:424
virtual const BinNode * maxNode() const
Definition bintree.hpp:342
virtual const BinNode * minNode(const BinNode *node) const
Returns the leaf node
Definition bintree.hpp:714
BinNode ** getNodeLocation(const BinNode *node)
Definition bintree.hpp:494
int removeAll()
Definition bintree.hpp:373
virtual const BinNode * root() const
Definition bintree.hpp:275
virtual int replaceNodeWithTheOnlyChild(BinNode *node)
Definition bintree.hpp:552
virtual int createIterator(Iterator **itr)
Definition bintree.hpp:405
int leafValues(List< T > *list)
Definition bintree.hpp:384
void setCompareCallback(int(*cb)(T a, T b))
Definition bintree.hpp:285
virtual int replaceNodeWithNode(BinNode *node, BinNode *replacement)
Definition bintree.hpp:589
L object() const
Definition list.hpp:58
Node * next() const
Definition list.hpp:50
int add(L obj)
Definition list.hpp:107
Node * first() const
Definition list.hpp:225
#define Delete(x)
Definition delete.hpp:9