go4gold
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
int find_max(int a[],int low,int high)
{ int max=0,index;
for(int i=low;i<=high;i++)
{
if(a[i]>max)
{
max=a[i];
index=i;
}
}
return index;
}
void addnode(int a[],int low,int high,node **root,node **ptr)
{
int k;
if(low>high)
return ;
else
{
node *temp= new node;
k=find_max(a,low,high);
temp->data=a[k];
temp->left=NULL;
temp->right=NULL;
if ( *root == NULL)
*root = temp;
*ptr=temp;
addnode(a,low,k-1,root,&(*ptr)->left);
addnode(a,k+1,high,root,&(*ptr)->right);
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
void search_next(node *p,node *q,int sum)
- go4gold April 25, 2012{
if(q==NULL)
return;
else if(q->data==sum)
printf("\n%d %d",p->data,q->data);
else
{
if (q->data > sum )
search_next(p,q->left,sum);
else
search_next(p,q->right,sum);
}
}
void find_pair(node *p,int sum)
{ static node *root=p;
if(p==NULL)
return;
else
{
if(p->data<(sum-(p->data)))
search_next(p,root,(sum-(p->data)));
}
find_pair(p->left,sum);
find_pair(p->right,sum);
}