您现在的位置是:主页 > news > 两学一做网站专题/seo免费入门教程
两学一做网站专题/seo免费入门教程
admin2025/5/13 14:06:50【news】
简介两学一做网站专题,seo免费入门教程,高端品牌男装,京东购物中心添加链接描述 中序、后序遍历建树 同时记录树的父亲,兄弟,高度,满二叉树,左右结点 #include<bits/stdc.h> using namespace std; const int N40; int post[N],in[N]; typedef struct node {int data,h;node *l,*r,*parent;…
两学一做网站专题,seo免费入门教程,高端品牌男装,京东购物中心添加链接描述 中序、后序遍历建树 同时记录树的父亲,兄弟,高度,满二叉树,左右结点
#include<bits/stdc.h>
using namespace std;
const int N40;
int post[N],in[N];
typedef struct node {int data,h;node *l,*r,*parent;…
添加链接描述
中序、后序遍历建树 同时记录树的父亲,兄弟,高度,满二叉树,左右结点
#include<bits/stdc++.h>
using namespace std;
const int N=40;
int post[N],in[N];
typedef struct node {int data,h;node *l,*r,*parent;
}*treenode;
bool full=1;
map<int,node*>mp;
string s;
node *build (int postl,int postr,int inl,int inr,int height){if(postl>postr)return NULL;treenode root;root=new node ();root->data=post[postr];root->h=height;int k=inl;while(in[k]!=post[postr])k++;root->l=build(postl,postl+(k-inl)-1,inl,k-1,height+1);root->r=build(postl+(k-inl),postr-1,k+1,inr,height+1);if(root->l!=NULL)root->l->parent=root;if(root->r!=NULL)root->r->parent=root;if((root->l!=NULL&&root->r==NULL)||(root->r!=NULL&&root->l==NULL))full=0;mp[post[postr]]=root;return root;
}
int n;
bool solve(){int x,y;if(s.find("root")!=string::npos){sscanf(s.c_str(),"%d is the root",&x);// return x==post[n];if(x==post[n])return 1;else return 0;}else if(s.find("siblings")!=s.npos){sscanf(s.c_str(),"%d and %d are siblings",&x,&y);return mp[x]->parent==mp[y]->parent;}else if(s.find("parent")!=s.npos){sscanf(s.c_str(),"%d is the parent of %d",&x,&y);return mp[y]->parent==mp[x];}else if(s.find("left")!=s.npos){sscanf(s.c_str(),"%d is the left child of %d",&x,&y);return mp[y]->l==mp[x];}else if(s.find("right")!=s.npos){sscanf(s.c_str(),"%d is the right child of %d",&x,&y);return mp[y]->r==mp[x];}else if(s.find("level")!=s.npos){sscanf(s.c_str(),"%d and %d are on the same level",&x,&y);return mp[x]->h==mp[y]->h;}else {return full;}
}int main(){treenode root;cin>>n;for(int i=1;i<=n;i++){cin>>post[i];}for(int i=1;i<=n;i++){cin>>in[i];}root=build(1,n,1,n,1);int q;cin>>q;getchar();while(q--){getline(cin,s);// cout<<s<<endl;if(solve()){puts("Yes");}else puts("No");}return 0;
}