Guest User

Untitled

a guest
Feb 27th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <memory>
  2.  
  3. template<typename Key, typename Value>
  4. struct Node
  5. {
  6.     using NodeType = Node<Key, Value>;
  7.     Key key;
  8.     Value value;
  9.    
  10.     std::unique_ptr<NodeType> left, right;
  11.    
  12.     bool operator<(NodeType& other) const noexcept
  13.     {
  14.         return key < other.key;
  15.     }
  16. };
  17.  
  18. template<typename Key, typename Value>
  19. class Tree
  20. {
  21. private:
  22.     std::unique_ptr<Node<Key, Value>> root;
  23.     using NodeType = Node<Key, Value>;
  24.    
  25. public:
  26.     // Questi 4 funzionano grazie ad unique_ptr
  27.     Tree() = default;
  28.     Tree(Tree&&) = default;
  29.     Tree& operator=(Tree&&) = default;
  30.     ~Tree() = default;
  31.    
  32.     // Se vuoi anche i costruttori di copia dovrai definirli tu
  33.     Tree(Tree const &);
  34.     Tree& operator=(Tree const &);
  35.    
  36.    
  37.     // Uso 'auto' in quanto il tipo che ritorna una di queste funzioni
  38.     // รจ molto soggettivo:
  39.     // A) Iteratore
  40.     // B) Reference a *this
  41.     // C) Booleano
  42.     // D) Altro
  43.    
  44.     auto insert(NodeType const &);
  45.     auto emplace(Key&&, Value&&);
  46.    
  47.     auto remove(NodeType const &);
  48.     auto remove(Key&&);
  49.    
  50.     auto find(NodeType const &);
  51.     auto find(Key&&);
  52. };
Advertisement
Add Comment
Please, Sign In to add comment