tttree.h

来自「经典c++程序的实现」· C头文件 代码 · 共 40 行

H
40
字号
class TT {
private:
  TTNode* root;
  void clearhelp(TTNode*)                // Helper functions
    { cout << "Clearhelp not yet defined\n"; }
  void inserthelp(TTNode*&, const TELEM&, TELEM&, TTNode*&);
//  void removehelp(TTNode*&, const TELEM&);
  TTNode* findhelp(TTNode*, const TELEM&) const;
  void printhelp(TTNode*, int) const;
public:
  TT() { root = NULL; }
  ~TT() { clearhelp(root); }
  void clear()
    { clearhelp(root); /* root = NULL; */ }
  void insert(const TELEM& val) { // Insert node with value val
    TELEM retval;             // Smallest value in newly created node
    TTNode* retptr = NULL;    // Newly created node
    cout << "Insert " << val << "\n";
    inserthelp(root, val, retval, retptr);
    if (retptr != NULL) {     // Root overflowed: make new root
      TTNode* temp = new TTNode;  temp->lkey = retval;
      temp->left = root; temp->center = retptr;
      temp->NumKeys = 1; root = temp;
    }
    return;
  }
  void remove(const TELEM& val)
    { cout << "Remove not implemented\n"; }
//    { removehelp(root, val); return *this; }
  TTNode* find(const TELEM& val)
    { cout << "Find " << val << ": "; return findhelp(root, val); }
  bool isEmpty() const
    { cout << "isEmpty: "; return root == NULL; }
  void print() const {
    cout << "Print tree: \n";
    if (root == NULL) cout << "The 2-3 Tree is empty.\n";
    else printhelp(root, 0);
  }
};

⌨️ 快捷键说明

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