本节比较短,主要贴出树的递归遍历,用前序中序后序三种方式
void preorder(mytree *root)//前序,根左右
{
if(root==NULL) return;
cout<<root->data<<endl;
preorder(root->left);
preorder(root->right);
}
void inorder(mytree *root)//中序
{
if(root==NULL) return;
inorder(root->left);
cout<<root->data<<endl;
inorder(root->right);
}
void postorder(mytree *root)//后序
{
if(root==NULL) return;
postorder(root->left);
postorder(root->right);
cout<<root->data<<endl;
}