void  BinarySearchTree<T>::traversePreorder(Node<T> *curNode) {
  if(curNode) {
    std::cout << " " << curNode->getElement();
    traversePreorder(curNode->getLeft());
    traversePreorder(curNode->getRight());
  }
}
void BinarySearchTree<T>::traversePreorder() {
  std::cout << "Tree Preorder traversal: ";
  if(!root) 
    std::cout << "(nil)";
  traversePreorder(root);
  std::cout << "\n";
}
Пример #3
0
// post order traversal. 
void traversePostorder(BTreeNode *head, vector<int> &vals) {
  if(NULL == head) return; 

  traversePreorder(head->left); 
  traversePostorder(head->right);
  vals.push_back(head->val); 
}