sk
BAN USER- 0of 0 votes
AnswersWrite a program to find out the sum of nodes which does not have siblings in a binary tree
I have written following logic and he was impressed with the logic, I think I did well but could not able write the logic for the traversing as I was not prepared but he said explain what is want to do and I explained, hoping for good results.
- skpublic int returnNodeValue(Node t) { BOOL thereIsNoLeft = false; BOOL thereIsNoRight = false; int returnValue = 0; if(t.left != null) { thereIsNoLeft = true; returnValue = t.left.value; } if(t.right != null) { thereisNoRight = true; returnValue = r.right.value; } if(!(thereIsNoLeft && thereisRight)) { return returnValue; } return 0; }
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
Thank you for the code, I have the main function and where I will traverse the tree, I only pasted the logic which Interviewer interested in.
- sk June 11, 2011Thanks again.