Skip to content

Commit

Permalink
stack trace: before separate file. deserialize done.
Browse files Browse the repository at this point in the history
  • Loading branch information
mumurik committed May 18, 2010
1 parent fe51adc commit c4d10e2
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 3 deletions.
25 changes: 25 additions & 0 deletions mona/include/sys/BinaryTree.h
Expand Up @@ -16,6 +16,7 @@ template <class T> class BinaryTree {
public:
int size() const;
T get(const int key) const;
T get_lower_nearest(const int key) const;
bool contains(const int key) const;
T add(const int key, const T element);
T remove(const int key);
Expand All @@ -37,6 +38,8 @@ template <class T> class BinaryTree {
void clear();
void clear(Node*& tree);
T get(const Node* tree, const int key) const;
T get_lower_nearest(const Node* tree, const int key) const;

};

template <class T> BinaryTree<T>::BinaryTree() : root_(NO_DATA), numberOfElements_(0) {
Expand All @@ -54,6 +57,10 @@ template <class T> T BinaryTree<T>::get(const int key) const {
return get(root_, key);
}

template <class T> T BinaryTree<T>::get_lower_nearest(const int key) const {
return get_lower_nearest(root_, key);
}

template <class T> void BinaryTree<T>::clear() {
clear(root_);
}
Expand Down Expand Up @@ -82,6 +89,24 @@ template <class T> T BinaryTree<T>::get(const Node* tree, const int key) const {
}
}

template <class T> T BinaryTree<T>::get_lower_nearest(const Node* tree, const int key) const {

if (tree == NO_DATA) {
return (T)0;
}

if (key == tree->key) {
return tree->element;
} else if (key < tree->key) {
return get_lower_nearest(tree->left, key);
} else {
T ret = get_lower_nearest(tree->right, key);
if(ret == (T)0)
return tree->element;
return ret;
}
}

template <class T> void BinaryTree<T>::clear(Node*& tree) {

if (tree != NO_DATA) {
Expand Down

0 comments on commit c4d10e2

Please sign in to comment.