there was error in else part and one more while loop was missing :-
here is the correct algo:-
while(!isEmpty(s1) || !isEmpty(s2))
{
while(!isEmpty(s1))
{
val=pop(s1);
print : val-data;
by zig-zag order means level order traversal ???
On Sun, Dec 11, 2011 at 6:22 AM, AMAN AGARWAL mnnit.a...@gmail.com wrote:
Hi,
Given a tree, in addition to the left and right pointer, it has a third
pointer, that is set to NULL.
Set the third pointer to a node, which will be the successor
@atul zig-zag mean spiral traversal of tree e.g. alternate the level while
traversing , if previous traversal is left to right , then next level will
be right to left .
@aman .quest has little ambiguity its says successor but ebvery nodes can
have we can ore-order , inorder ,postorder
Hi,
Suppose we have a binary search tree as 15,12,18,17,21,11,14
then O/P will be 15 12 18 21 17 14 11.
so the successor of 15 is 12 the successor of 12 is 18 and so on.
I hope now its clear.
Regards,
Aman.
On Sun, Dec 11, 2011 at 6:26 PM, WgpShashank shashank7andr...@gmail.comwrote:
@atul
@Gene : if i am not wrong , level order traversal can be done using only 1
queuewhy 2 queue???
On Sun, Dec 11, 2011 at 9:53 PM, AMAN AGARWAL mnnit.a...@gmail.com wrote:
Hi,
Suppose we have a binary search tree as 15,12,18,17,21,11,14
then O/P will be 15 12 18 21 17 14 11.
so the
we have to traverse in zig zaz or spirally. so we need two stack or two
queus.
On Mon, Dec 12, 2011 at 12:23 AM, atul anand atul.87fri...@gmail.comwrote:
@Gene : if i am not wrong , level order traversal can be done using only 1
queuewhy 2 queue???
On Sun, Dec 11, 2011 at 9:53 PM, AMAN
Hi,
Yes.
Regards,
Aman.
On Sun, Dec 11, 2011 at 12:54 PM, atul anand atul.87fri...@gmail.comwrote:
by zig-zag order means level order traversal ???
On Sun, Dec 11, 2011 at 6:22 AM, AMAN AGARWAL mnnit.a...@gmail.comwrote:
Hi,
Given a tree, in addition to the left and right pointer, it
so algo for zig-zag using two stack would be like this :-
let* two stack s1,s2;*
toggle = -1;
push(root,s1);
while ( !isEmpty(s1) || ! isEmpty(s2))
{
while( ! isEmtpy(s1))
{
print : val=pop(s1);
if(toggle == -1)
{
if(val-right)
Hi,
Given a tree, in addition to the left and right pointer, it has a third
pointer, that is set to NULL.
Set the third pointer to a node, which will be the successor of the current
node, when the tree is traversed in the zig-zag order. In other words, if
we traverse the tree using this third