Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void printTree(int & a)
- {
- cout << a << endl;
- }
- handler::handler()
- {
- }
- void handler::printTree()
- {
- BinarySearchTree<int> tree;
- tree.insert(10);
- tree.insert(5);
- tree.insert(2);
- tree.insert(20);
- tree.inorder(printTree);
- }
- #include <iostream>
- #include "BinarySearchTree.h"
- #include "handler.h"
- int main()
- {
- handler handle;
- handle.printTree();
- }
- template<class T>
- inline void BinarySearchTree<T>::inorder(Node * root, void(*inorderPtr)(T &)) const
- {
- if (root != nullptr)
- {
- if (root->left != nullptr)
- {
- inorder(root->left, inorderPtr);
- }
- inorderPtr(root->data);
- if (root->right != nullptr)
- {
- inorder(root->right, inorderPtr);
- }
- }
- else
- {
- cout << "No data" << endl;
- }
- }
- template<class T>
- inline void BinarySearchTree<T>::inorder(void(*inorderPtr)(T &)) const
- {
- inorder(this->root, inorderPtr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement