Help me!! I get SIGSEGV in an online IDE while in my computer it works

My code is giving me SIGSEGV in an online IDE while in my computer it works, everything seems good for me, please help me only to understand my problem not necessarily  the solution. Here is the code with comments:

#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct Node{
	 int val;
	 Node *fG;
	 Node *fD;
}node;

node *newNode(int val){
	node *nouveau=(node*)malloc(sizeof(node));
	nouveau->val=val;
	nouveau->fG=NULL;
	nouveau->fD=NULL;
}
node *initializeABR(int val){
	return(newNode(val));
}
void buildABR(node *root,int val){
	if(root->val>val){
		if(root->fG==NULL){
			root->fG=newNode(val);
		}else{
			buildABR(root->fG,val);
		}
	}else{
		if(root->fD==NULL){
			root->fD=newNode(val);
		}else{
			buildABR(root->fD,val);
		}
	}
}
bool findR(node *root,int R){//it returns true when it finds R in BST where evry node have only one children
	if(R>root->val){
		if(root->fG==NULL){
			return(true && findR(root->fD,R));
		}else return false;
	}else if(R<root->val){
		if(root->fD==NULL){
			return(true && findR(root->fG,R));
		}else return false;
	}else return true;
}
void deleteABR(node *root){
	if(root==NULL) return;
			supprimerABR(root->fD);
			supprimerABR(root->fG);
			free(root);
}
int main(){
	int t,n,r;// t: the number of test cases // n:the number of nodes//r: the value i seek for
	int val;//the value of the node i will get from stdin
	cin>>t;
	node *root[50];//a table of roots of binary search trees
	while(t--){
		cin>>n>>r;
		int k=n;
		cin>>val;
		k--;
		root[t]=initializeABR(val);
		while(k--){
			cin>>val;
			buildABR(root[t],val);//I insert the value val in a binarySearchTree of root (root[t])
		}
		if(findR(root[t],r)){//return true only if when i seek for "r" if  less than the value
							//of root I should go to left and the right children should be NULL
							//The inerse if r>root.value(all values are different)
							//Brief: (the BST should not have two children to return true)
			//exemple: when the values of input are
			/*n=5 r=890
				5123 3300 783 1111 890*/
			printf("YES\n");
		
		}else printf("NO\n");//return false if i found that the a BST with two children
			/*n=5 r=200
				600 300 100 350 200
				I should get NO*/
		deleteABR(root[t]);
	}
	return 0;
}

Author: Aminovish
Login to Answer
Sort By:
Oldest
|
Newest
|
Vote
|
My Answer