Advertisement
vkichukova

Untitled

Feb 5th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. void printBFS(Node<T>* _root)
  2. {
  3. if(_root)
  4. {
  5. queue<Node<T>*> q;
  6. q.push(_root);
  7. while(!q.empty())
  8. {
  9. Node<T> *helper = q.front();
  10. q.pop();
  11. cout << helper->data << " ";
  12. if(helper->left)
  13. q.push(helper->left);
  14. if(helper->right)
  15. q.push(helper->right);
  16. }
  17. }
  18. }
  19. void printDFS(Node<T>* _root)
  20. {
  21. if(_root)
  22. {
  23. cout << _root->data << " ";
  24. printHelpDFS(_root->left);
  25. printHelpDFS(_root->right);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement