The below code for the mirror tree was working super fine on my laptop but not on coding blocks platform why so?

include <bits/stdc++.h>

include

using namespace std;

vector v;

char a[100000];

//class node
class node{

public:

	int data;

	node *left,*right;

public:

	node(int val){

	data = val;

	*left = *right = NULL;

	}

};

//string to int from single line of space chars

void stringToInt(){

char *ans = strtok(a," ");

while(ans != NULL){

	v.push_back(stoi(ans));

	ans = strtok(NULL," ");

}

}

//create tree

node* createTree(){

if(v.size()==0){return NULL;}

int no = v[0];

node* root = new node(no);

int i=0;

int flag = 0;

queue<node*> q;

while(!q.empty() && i<v.size()){

	node* temp = q.front();


	q.pop();



	no = v[i++];

	if(no!=-1){

		temp->left = new  node(no);

		q.push(temp->left);

	}

	if(i>=v.size()){ break;}

	no = v[i++];

	if(no!=-1){

		temp->right = new node(no);

		q.push(temp->right);

	}

	if(i>=v.size()){ break; }
	

}
return root;

}

//mirror tree

bool isMirror(node* root){

if(root->left == NULL && root->right == NULL){ return true;}

if(root->left == NULL || root->right == NULL){ return false;}

return (root->left->data == root->right->data)&&(isMirror(root->left))&&(isMirror(root->right));

}

//main fn

int main(){

cin.ignore();

cin.getline(a,' ');

stringToInt();

node* root = createTree();	

cout << isMirror(root) << endl;

return 0;

}

Hey @hemu1999
Please share your code in coding blocks IDE :slight_smile:

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.