what we have to do when value of n and m are different in this question
About n and m values when different
hi @devashishbotre95_45ed0bc0d0c42ff0 cant be different else tree wont be possible, no such cases will be given
what is wrong in my code, sir
#include #include using namespace std; class node { public: int data; nodeleft; noderight; node(int d) { data=d; left=NULL; right=NULL; } }; node* build(int pre,int in,int s,int e) { static int i=0; if(s>e) { return NULL; } noderoot=new node(pre[i]); int index=-1; for(int j=s;s<=e;j++) { if(in[j]==pre[i]) { index=j; break; } } i++; root->left=build(in,pre,s,index-1); root->right=build(in,pre,index+1,e); return root; } void printpre(noderoot) { if(root==NULL) { return; } if(root->left==NULL) { cout<<βENDβ; } else { cout<left->data; } cout<<" => β<data<<β <= "; if(root->right==NULL) { cout<<βENDβ<<endl;; } else { cout<right->data<<endl;; } printpre(root->left); printpre(root->right); return; } int main() { int n,m; cin>>n; int pre[n]; for(int i=0;i<n;i++) { cin>>pre[i]; } cin>>m; int in[m]; for(int i=0;i<m;i++) { cin>>in[i]; } node*root=build(pre,in,0,n-1); printpre(root); return 0; }
hi @devashishbotre95_45ed0bc0d0c42ff0 please send on ide.codingblocks.com
the code is not readable here
- login
- write
- save
- send the url of page
sir, code is not working again