@Mihir Just understood what you were asking...
atul is nearly right. You got to remove the unused items from LinkedList after calling "print(left,..") and "print(right, ..)", which might contain more than one item. Since I'm not a Java guy, I just wrote some snippet using F# to illustrate the idea. Hope it helps. type BinaryTree<'a> = | Node of BinaryTree<'a> * BinaryTree<'a> * 'a | None let rec PrintPath (root : BinaryTree<'a>) list = match root with | None -> () | Node(left, right, value) -> let list = value :: list PrintPath left list PrintPath right list if left = None && right = None then printfn "%A" (List.rev list) let tree = Node(Node(Node(None, None, 1), Node(None, None, 5), 2), None, 7) let list = [] PrintPath tree list -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.