madhukits@yahoo.com
BAN USER
Comments (4)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
-3
of 3 vote
Node* findMiddleNode(Node* aNode)
{
Node* midNode = aNode;
while(aNode->Next!=NULL && aNode->Next->Next!=NULL)
{
midNode = aNode;
aNode = aNode->Next->Next;
}
return midNode;
}
In the above case we are not traversing but just updating the middle node to correct location.
- madhukits@yahoo.com September 30, 2011Comment hidden because of low score. Click to expand.
0
of 0 vote
Good One. There is a small change needed in the program.
We have to store BSTNode* lastPrint in global storage and update we cannot pass in the function. Because the stack will pop the lastPrint Value as you are using recursion.
Comment hidden because of low score. Click to expand.
1
of 1 vote
Is there any specific reason for choosing the circle in this question?
- madhukits@yahoo.com September 27, 2011Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Yes the solution I gave is wrong and will always give the third node from the last.
- madhukits@yahoo.com October 06, 2011In the above solution you provided is using two node pointers and two traversals are happening.
If the question does not limit abt space and time, then array or hashing is correct. But we will loose the property of linked lists.
I dont think any such solution exists.