
namespace tree {

data_t& BinaryTree::find(key_t key) {
    if(!root_.is_not_leaf()) {
      throw not_found_exception();
    }
    
    element_t* tmp_element = *root_;
    do {
      if(tmp_element->key() < tmp_element.left().key()) {
	tmp_element = tmp_element->left();
      } else {
	tmp_element = tmp_element->right();
      }
    } while(tmp_element.is_not_leaf());
    
    if(tmp_element->key() == key) {
      return tmp_element->data();
    } else {
      throw not_found_exception(key);
    }
}

} // end tree namespace
