we need to use queue and stack alternately ... once we handle this , i think it should be straight forward to code ...
On Nov 20, 9:27 am, dinesh bansal <[email protected]> wrote: > On Wed, Nov 18, 2009 at 8:05 AM, Nayn <[email protected]> wrote: > > Hi guys, > > Recently I came across a problem. We've to display a binary tree in > > spiral. > > 1. We need to print the nodes in BFS manner. > > 2. The nodes should be displayed in alternate direction; in one level > > from left to right and in next level right to left. > > Needless to mention, we need least time complex solution. > > Thanks > > Nayn > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<algogeeks%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=. > > > If its just about display, you can traverse the tree in BFS manner and > > store the nodes in an array at their specific locations. At the end, display > the nodes from the array. > > Thanks, > -- > Dinesh Bansal > The Law of Win says, "Let's not do it your way or my way; let's do it the > best way." -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=.
