简单的不用考虑平衡的二叉查询树;我发现我有读题障碍症。。。
#include#include #include #include using namespace std;using std::vector;int n;struct node{ int data; node* lchild; node* rchild;};vector input;vector inorder_;vector change_inorder_;vector postorder_;vector change_postorder_;node* newNode(int x){ node* root=new node; root->lchild=NULL; root->data=x; root->rchild=NULL; return root;}void insert(node* &root,int x){ if(root==NULL){ root=newNode(x); return ; } if(x data){ insert(root->lchild,x); }else{ insert(root->rchild,x); } return ;}void inorder(node* root,vector & vi){ if(root==NULL) return; vi.push_back(root->data); inorder(root->lchild,vi); inorder(root->rchild,vi);}void postorder_change(node* root){ if(root==NULL) return; postorder_change(root->lchild); postorder_change(root->rchild); swap(root->lchild,root->rchild);}void postorder(node* root,vector & vi){ if(root==NULL) return; postorder(root->lchild,vi); postorder(root->rchild,vi); vi.push_back(root->data);}int main(){ int mem; node* root=NULL; scanf("%d",&n); for(int i=0;i