Guest User

BSTDict.hpp

a guest
Mar 11th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. //BSTDict.hpp
  2. #ifndef _BSTDICT_HPP
  3. #define _BSTDICT_HPP
  4.  
  5. #include "Compare.hpp"
  6. #include "PredDict.hpp"
  7.  
  8. // It's annoying, but templated classes are best defined in a single file.  So, we just
  9. // include the .cpp file at the end of the .hpp.  See the end of this file.
  10.  
  11. // An implementation of a dictionary ADT as a binary search tree (without balancing
  12. // operations).
  13. //
  14. // The template type means that the dictionary will store elements with key type T, and
  15. // data type T; and two elements of type T will be compared using the operator() of a
  16. // Compare class.
  17.  
  18. template <typename T, class Compare>
  19. class BSTDict : public PredDict<T> {
  20. public:
  21.     BSTDict();
  22.     ~BSTDict();
  23.     bool find(T key, T& pred);
  24.     void add(T key, T pred);
  25.    
  26. private:
  27.     // 221 STUDENTS:  Put any private members and functions here.
  28.     // I suggest you have this Node type and root variable at least.
  29.     struct Node {
  30.         T key;
  31.         T data;
  32.         Node* left;
  33.         Node* right;
  34.     };
  35.    
  36.     Node* root;
  37.    
  38.     // Any helper fuctions should be declared here, too
  39.     bool find_helper(Node* r, T key, T& pred);
  40.     Node*& add_helper(Node*& r, T key);
  41. };
  42.  
  43. #include "BSTDict.cpp"
  44.  
  45. #endif
Advertisement
Add Comment
Please, Sign In to add comment