JiM.iiitm
BAN USERStudent hoo yar ..
Did my internship in MS.
for further detail contact
jim.iiitm@gmail.com
we can go column wise
for eg
111000
110000
111100
000000
so in this case if we move column wise then we can get the ans
scan 1st row till 0 is found. term it as max row.jump to 2nd row same column N chk if it is 1 then move righthand side row wise otherwise jump to next row.
hey if it means writing in file then we can go like this..
file will contain
1
23
4567
for empty child let put x.
so the code will be
int a=1,b=1;
s.push(root);
while(a!=0)
{
b=a;
a=0;
while(b>0)
{
p=s.pop();
if(p==X)
{
end loop;
}
if(p.left)
{
s.push(p.left);
a++;
}
if(p.right)
{
s.push(p.right);
a++;
}
Print p;
b--;
}
print Space;
}
\\ this code if for complete tree which doesnt miss any single child.
\\ Here if any child doesnot exist then assume it X.
hey i think we can solve this recursivly ...
- JiM.iiitm July 11, 2010here i m taking assumption that both linkedlist r of same size.
int sum(Node * s1, Node *s2)
{
static int j=1;
if (s1==NULL || s2 == NULL)
return 0;
int i=sum(s1->next,s2->next);
i=(s1->data+s2->data)*j + i;
return i;
}
it will process like this ...
s1 = 9-8-7-6
s2=9-9-9-9
sum = (6+9)+10*(7+9)+100*(8+9)...