Advertisement
kaenan

btree.h

Feb 27th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #pragma once
  2.  
  3. #ifndef __BTREE_H
  4. #define __BTREE_H
  5.  
  6. #include <fstream>
  7. #include <functional>
  8. #include <vector>
  9. #include <memory>
  10.  
  11. template<typename T>
  12. class btree
  13. {
  14. public:
  15.     struct Node {
  16.         T data;
  17.         int depth;
  18.         std::shared_ptr<Node> left, right;
  19.     };
  20.  
  21.     /* Create node, fill in data and return. */
  22.     std::shared_ptr<Node> create_node(T data);
  23.  
  24.     std::shared_ptr<Node> read_traversal_body(
  25.         std::istream&, std::istream&,
  26.         std::function<bool(std::istream&, T&)>,
  27.         std::function<bool(std::istream&, T&)>,
  28.         std::function<bool(std::vector<T>, T)>,
  29.         std::vector<T>&);
  30.  
  31.     void read_traversal(
  32.         std::istream&, std::istream&,
  33.         std::function<bool(std::istream&, T&)>,
  34.         std::function<bool(std::istream&, T&)>,
  35.         std::function<bool(std::vector<T>, T)>
  36.         );
  37.  
  38.     /* Read a tree. */
  39.     std::shared_ptr<Node> read_preorder_body(std::istream&, std::function<bool(std::istream&, T&)>);
  40.     void read_preorder(std::istream&, std::function<bool(std::istream&, T&)>);
  41.  
  42.     /* Preorder traversal. Returns depth. */
  43.     int preorder_traversal(std::function<void(T& data)>);
  44.  
  45.     /* Breadth traversal. Return ptr to the last node. */
  46.     std::shared_ptr<Node> breadth_traversal(std::function<void(T&)>);
  47.  
  48. private:
  49.     std::shared_ptr<Node> root;
  50. };
  51.  
  52. #include "btree.cpp"
  53.  
  54. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement