tag:blogger.com,1999:blog-694855878384792308.post412992489294413806..comments2024-03-21T06:26:49.387-07:00Comments on Java67: Post Order Binary Tree Traversal in Java Without Recursion - Example Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-694855878384792308.post-38584156969874781022020-04-17T03:15:48.036-07:002020-04-17T03:15:48.036-07:00Hi @Unknown, thanks will check it out. Hi @Unknown, thanks will check it out. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-69364442271228314612020-04-14T05:33:07.028-07:002020-04-14T05:33:07.028-07:00@ That's a better solution using one more poin...@ That's a better solution using one more pointer "lastPrintedNode". It Works! Lakshmihttps://www.blogger.com/profile/17504225143138113709noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-55514914477571304942020-01-13T04:12:33.413-08:002020-01-13T04:12:33.413-08:00There is an issue with the diagram that is used. I...There is an issue with the diagram that is used. It is not consistent with the code.Anonymoushttps://www.blogger.com/profile/18105954587502777641noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-25955621566673261672019-06-29T15:06:59.393-07:002019-06-29T15:06:59.393-07:00I think it's better to use solution without ch...I think it's better to use solution without changing data in nodes.<br /><br /> public static void postOrderTraversalWithoutRecursion(BinaryTree binaryTree) {<br /> Node top = binaryTree.top;<br /> if(top == null) {<br /> System.out.println("Empty Binary Tree");<br /> return;<br /> }<br /> Stack stack = new Stack<>();<br /> stack.push(top);<br /> Node lastPrintedNode = top;<br /> Node current;<br /> while (!stack.isEmpty()) {<br /> current = stack.pop();<br /> if(current.isLeaf() || lastPrintedNode == current.right || lastPrintedNode == current.left) {<br /> System.out.printf("%s, ", current.value);<br /> lastPrintedNode = current;<br /> } else {<br /> stack.push(current);<br /> if(current.right != null) {<br /> stack.push(current.right);<br /> }<br /> if(current.left != null) {<br /> stack.push(current.left);<br /> }<br /> }<br /> }<br /> }Anonymoushttps://www.blogger.com/profile/15250797614003690697noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-57513097004551072092018-11-16T06:35:13.296-08:002018-11-16T06:35:13.296-08:00That's a bit presumptuous destroying the origi...That's a bit presumptuous destroying the original data... Instead of doing that, you could keep track of hosts already output in a HashSet.Anonymousnoreply@blogger.com