Create tree from inorder and preorder


why this code is giving segmentation fault

Dakshi… The print function you have written in your code is wrong… Pls use the approach as,
if(root == NULL)
{
return;
}
if(root->left != NULL && root->right == NULL)
{
cout << root->left->data << " => " << root->data << " <= " << “END” << endl;
}
if(root->left == NULL && root->right == NULL)
{
cout << “END => " <data << " <= END” << endl;
}
if(root->left == NULL && root->right != NULL)
{
cout << "END => " << root->data << " <= " << root->right->data << endl;
}
if(root->left != NULL && root->right != NULL)
{
cout << root->left->data << " => " << root->data << " <= " << root->right->data << endl;
}
preOrder(root->left);
preOrder(root->right);

Also I have edited buildtree function of your code as welll… Pls see to it…