Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void printTree(int & a)
  5. {
  6. cout << a << endl;
  7. }
  8.  
  9. handler::handler()
  10. {
  11.  
  12. }
  13.  
  14.  
  15. void handler::printTree()
  16. {
  17.  
  18. BinarySearchTree<int> tree;
  19.  
  20. tree.insert(10);
  21. tree.insert(5);
  22. tree.insert(2);
  23. tree.insert(20);
  24.  
  25. tree.inorder(printTree);
  26. }
  27.  
  28. #include <iostream>
  29.  
  30. #include "BinarySearchTree.h"
  31. #include "handler.h"
  32.  
  33.  
  34. int main()
  35. {
  36. handler handle;
  37.  
  38. handle.printTree();
  39. }
  40.  
  41. template<class T>
  42. inline void BinarySearchTree<T>::inorder(Node * root, void(*inorderPtr)(T &)) const
  43. {
  44. if (root != nullptr)
  45. {
  46. if (root->left != nullptr)
  47. {
  48. inorder(root->left, inorderPtr);
  49. }
  50. inorderPtr(root->data);
  51. if (root->right != nullptr)
  52. {
  53. inorder(root->right, inorderPtr);
  54. }
  55. }
  56. else
  57. {
  58. cout << "No data" << endl;
  59. }
  60. }
  61.  
  62. template<class T>
  63. inline void BinarySearchTree<T>::inorder(void(*inorderPtr)(T &)) const
  64. {
  65. inorder(this->root, inorderPtr);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement