#include #include #include "book.h" #include "binnode.h" // Stick these in to test the preorder routine #define visit(X) (cout << X->val() << endl) template void preorder(BinNode* subroot) { if (subroot == NULL) return; // Empty subtree, do nothing visit(subroot); // Perform whatever action is desired preorder(subroot->left()); preorder(subroot->right()); } template int count(BinNode* subroot) { if (subroot == NULL) return 0; // Nothing to count return 1 + count(subroot->left()) + count(subroot->right()); } // Test the preorder traversal routines int main() { BinNodePtr* root = new BinNodePtr(10); root->setLeft(new BinNodePtr(15)); root->setRight(new BinNodePtr(20)); preorder(root); cout << " Count is: " << count(root) << endl; }