Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. Node<D> *get_head() {
  2. return _head;
  3. }
  4.  
  5. void TerTree<T>::map_element(TerTree<T> *tree, const Node<T> *node, T(*func)(const T &)) const;
  6.  
  7. void TerTree<T>::map(TerTree<T> *tree, T(*func)(const T &)) const;
  8.  
  9.  
  10. ^^^^^^^^^^^ VSE ETO V class TerTree
  11.  
  12. template <class T>
  13. void TerTree<T>::map_element(TerTree<T> *tree, const Node<T> *node, T(*func)(const T &)) const {
  14. if (node) {
  15. tree->addNode(func(node->getData()));
  16. if (node->getLeft())
  17. map_element(tree, node->getLeft(), func);
  18. if (node->getCenter())
  19. map_element(tree, node->getCenter(), func);
  20. if (node->getRight())
  21. map_element(tree, node->getRight(), func);
  22.  
  23.  
  24. }
  25. }
  26.  
  27. template <class T>
  28. void TerTree<T>::map(TerTree<T> *tree, T(*func)(const T &)) const {
  29. if (!tree) {
  30. cout << "Nullptr passed as destination tree." << endl;
  31. return;
  32. }
  33. if (!func) {
  34. cout << "Nullptr passed as function." << endl;
  35. return;
  36. }
  37. map_element(tree, this->get_head(), func);
  38. }
  39.  
  40. ^^^^^^^^^^^^^^^^^^^^^^^^^ VSE ETO VNE KLASSA TerTree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement