8 #ifndef __BINARY_TREE_H__
9 #define __BINARY_TREE_H__
12 #include "tools/GenericException.h"
13 #include "tools/NoCopy.h"
52 void add(
const Item &item) {
59 "Cannot allocate new Item");
71 bool find(
const Item &item) {
76 if (item == n->
_item)
return true;
78 if (item < n->_item) {
88 void traverse(
void (*visit) (
const Item &,
void *),
void *arg=0) {
89 visit_inorder (visit, _root, arg);
102 }
else if (new_item->
_item < (*node)->_item) {
103 insert(new_item, & ((*node)->_left));
105 insert(new_item, & ((*node)->_right));
109 void visit_inorder(
void (*visit) (
const Item &,
void *),
112 visit_inorder(visit, node->
_left, arg);
113 visit(node->
_item, arg);
114 visit_inorder(visit, node->
_right, arg);
120 cleanup(node->
_left);
bool find(const Item &item)
Try to find item in tree.
Definition: BinaryTree.h:71
Binary tree item.
Definition: BinaryTree.h:20
BinaryTreeItem * _left
left pointer
Definition: BinaryTree.h:30
Item _item
item
Definition: BinaryTree.h:29
BinaryTreeItem * _right
right pointer
Definition: BinaryTree.h:31
void traverse(void(*visit)(const Item &, void *), void *arg=0)
Sorted (inorder) traverse, calling visitor routine on each item.
Definition: BinaryTree.h:88
void add(const Item &item)
Add (copy) Item into the tree.
Definition: BinaryTree.h:52
Generic Exception: Base class for exceptions.
Definition: GenericException.h:45
BinaryTreeItem()
Constructor.
Definition: BinaryTree.h:24
Sorted binary tree for Items that support the "less than" and "equal" operators.
Definition: BinaryTree.h:42