stree.cpp

来自「数据结构与程序设计教材源码 数据结构与程序设计教材源码」· C++ 代码 · 共 49 行

CPP
49
字号
 
template <class Record>
Error_code Search_tree<Record>::insert(const Record &new_data)
{
   return search_and_insert(root, new_data);
}
 
template <class Record>
Error_code Search_tree<Record>::remove(const Record &target)
/* 
 
Post:
If a Record with a key matching that of target 
belongs to the Search_tree a code of
success is returned and the corresponding node
is removed from the tree.  Otherwise,
a code of not_present is returned.
Uses: Function search_and_destroy
 
*/

{
   return search_and_destroy(root, target);
}
 
template <class Record>
Error_code Search_tree<Record>::tree_search(Record &target) const

/* 
 
Post:
If there is an entry in the tree whose key matches that in target,
the parameter target is replaced by the corresponding record from
the tree and a code of success is returned.  Otherwise
a code of not_present is returned.
Uses: function search_for_node
 
*/

{
   Error_code result = success;
   Binary_node<Record> *found = search_for_node(root, target);
   if (found == NULL)
      result = not_present;
   else
      target = found->data;
   return result;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?