Design a conventional iterative algorithm to traverse a binary tree represented in linked list in post order?
-
-
Answer:
PROCEDURE POSTORDER(T) [Given a binary tree whose root node address is given by the pointer variable T, this algorithm traverses the tree in postorder in an iterative manner]. 1. [Initialize] If T = NULL then write ("Empty Tree") return else P <-- T TOP <-- 0 Call push(S,TOP,T). 2. [Process each stack branch address] Repeat step 5 while TOP > 0. 3. [Descend left] while P != NULL call push(S,TOP,P) P <-- LPTR(P) 4. [Process a node whose left and right subtree have been processed] Repeat while S[TOP] > 0 P <-- pop(S,TOP) write DATA(P) if TOP = 0 return. 5. [Branch right and then mask node from which we branched] P <-- RPTR(S[TOP] S[TOP] <-- - S[TOP]. 6. [FINISH] return. Firdous The Great :) ICT Scholar.
community wiki at wiki.answers.com Visit the source
Related Q & A:
- How to find out if it is possible to contruct a binary matrix with given row and column sums?Best solution by Mathematics
- how to draw circular doubly linked list?Best solution by TeX - LaTeX
- How can I have my contact list in alphabetic order by name?Best solution by answers.microsoft.com
- How long does it take for an orange seed to grow from when it is a seed to when it is a tree?Best solution by wiki.answers.com
- What is a creative way to display a family tree?Best solution by geni.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.