TEST CASES SHOWING WRONG

#include
#include
using namespace std;

class node
{
public:
int data;
node *left;
node *right;

node(int d)
{
    data=d;
    left=NULL;
    right=NULL;
}

};

void Preorder(node *root)
{
queue<node *> q;
q.push(root);
while(!q.empty())
{
node *temp=q.front();
q.pop();

    if(temp->left!=NULL)
    {
        cout<<temp->left->data<<" => ";
        q.push(temp->left);
    }
    else
    {
        cout<<"END => ";
    }
    cout<<temp->data;
    
    if(temp->right!=NULL)
    {
        cout<<" <= "<<temp->right->data;
        q.push(temp->left);
    }
    else
    {
        cout<<" <= END";
    }
    cout<<endl;
}

}

node * Build_Tree(int *Pre,int *In,int s,int e)
{
static int i=0;

if(s>e)
  return NULL;

node *root=new node(Pre[i]);

int index=-1;
for(int j=s;j<=e;j++)
{
    if(In[j]==Pre[i])
    {
        index=j;
        break;
    }
}
i++;
root->left=Build_Tree(Pre,In,s,index-1);
root->right=Build_Tree(Pre,In,index+1,e);
return root;

}

int main()
{
int n,m;
cin>>n;
int *Pre=new int[n];
for(int i=0;i<n;i++)
cin>>Pre[i];

cin>>m;
int *In=new int[m];
for(int i=0;i<m;i++)
   cin>>In[i];

node *root=Build_Tree(Pre,In,0,n-1);
Preorder(root);

}

hi @Mukul-Shane-1247687648773500,
upadted https://ide.codingblocks.com/s/667728

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.