[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-09-11 Thread anshu
yeah..Sorry for the mistake .. I did not check boundary conditions correctly.. your correction should make it work perfectly.. We can also add a little optimization to not push the last one .. because as soon as its pushed its popped.. Thanks, -anshu Thanks, -anshu On Sep 9, 8:33 am, chandra

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-09-10 Thread chandra kumar
Hi, You are right. Thank you for the correction. Actually the error is because of the ignorance of the fact that not only the info about the left and right child are important but also the order in which the elements in the stack are pushed. So instead of having two stacks, this can be

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-09-10 Thread mirchi
can any one please tell me how to submit problems in the new acm site? i am not able to figure it out !!! On Sep 10, 8:50 pm, chandra kumar [EMAIL PROTECTED] wrote: Hi, You are right. Thank you for the correction. Actually the error is because of the ignorance of the fact that not only

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-09-10 Thread adak
For which ACM contest? They have regional events world-wide, and then of course, the finals in Alberta, Canada next year. For the latter, click here: http://icpc.baylor.edu/icpc/ For an explanation of one competition, go here: http://online-judge.uva.es/contest/running.html Enjoy!

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-09-08 Thread chandra kumar
Hi, But in your second while( ) loop when the check 'root-left = NULL' executes 'root' is already NULL, because only then the first loop terminates. So you need to insert the following statement inbetween the loops root = pop( ) Also your solution assumes that the value at the nodes

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-09-08 Thread Phani Kumar Ch. V.
Hi Chandra, First of all Post-order is not the one which prints root first and then its children. Post order means first processing of left and right subtree's and then the data in the node. For eg: 1 2 3 45 6 7 Post order is: 4 5 2 6 7 3 1 Pre order is: 1 2 4 5

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-08-27 Thread MD
I think first s=pop() in while is not the right approach. This is an alternate approach where explored() checks if the node is visited or not... hence discarding that path.. and I think the following handles the null conditions as well.. (ex given by chandra) void postOrderTraversal(Tree *root)

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-08-27 Thread chandra kumar
Hi, Need more details about explored( Node * ) function, Consider the NULL input if your explored( NULL ) returns true then I guess that every thing works fine, and also most of your checks could be eliminated ( code will become simpler ) if your explored( NULL ) returns false,

[algogeeks] Re: Post order traversal of a binary tree without recursion

2007-08-26 Thread chandra kumar
Hi, Consider the case given below, 2 1NULL The post order should be 1, 2 ( ignoring the NULL ). Your algo gives 2 as the result. Pin point me if I'm wrong. Thanks and Regards, K.V.Chandra Kumar. On 24/08/07, Phani Kumar Ch. V. [EMAIL PROTECTED]