1043 Is It a Binary Search Tree (25)(25 分)

模板题目:建立二叉搜索树,先序和后序遍历

#include
using namespace std;
struct node{
    int data;
    node *rchild,*lchild;
};
int a[1010],n;
vectorpre,premirror,post,postmirror;
void insert(node*&root,int x)
{
    if(root==NULL)
    {
        root=new node;
        root->data=x;
        root->lchild=root->rchild=NULL;
        return;
    }
    if(xdata)insert(root->lchild,x);
    else insert(root->rchild,x);
}
void preorder(node*root)
{
    if(root==NULL)return;
    pre.push_back(root->data);
    preorder(root->lchild);
    preorder(root->rchild); 
} 
void preordermirror(node*root)
{
    if(root==NULL)return;
    premirror.push_back(root->data);
    preordermirror(root->rchild);
    preordermirror(root->lchild);
}
void postorder(node*root)
{
    if(root==NULL)return;
    postorder(root->lchild);
    postorder(root->rchild);
    post.push_back(root->data);
}
void postordermirror(node*root)
{
    if(root==NULL)return;
    postordermirror(root->rchild);
    postordermirror(root->lchild);
    postmirror.push_back(root->data);
}
bool issame(vectorp)
{
    for(int i=0;ip)
{
    for(int i=0;i

你可能感兴趣的:(1043 Is It a Binary Search Tree (25)(25 分))