How to traverse linked list in c++?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.