basically I am trying to pass the pointer where address of new block needs to be stored
void buildseg(class node *p,int a[],int l,int r)
{
class node *temp;
temp=createnode();
int sum=0;
for(int i=l;i<=r;i++)
{
sum=sum + a[i];
}
temp->val=sum;
temp->leftrange=l;
temp->rightrange=r;
if(root==NULL)
{
root=temp;
}
if(l!=r)
{
int q=(l + r)/2;
buildseg(temp->left,a,l,q);
buildseg(temp->right,a,q+1,r);
}
else{
temp->left=NULL;
temp->right=NULL;
}
p=temp;
}
class node{
public:
int val;
int leftrange;
int rightrange;
class node *left;
class node *right;
};
class node *root=NULL;
class node *createnode()
{
class node *p;
p=(class node*)malloc(sizeof(class node));
return p;
}
can anyone help me where the error lies. Whether we can pass a pointer where we have to store address of a block created by malloc function. or it's wrong over there.