Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Recursive algorithm for traversing a binary tree in postorder in dfs (data file structure).

  Shared By: Rainart Fischer    Date: Sep 20    Category: C++ Programming    Views: 1551

Answer:

PROCEDURE RPOSTORDER(T)
[Given a binary tree whose root node address is given by the pointer variable T, this algorithm traverses the tree in postorder in a recursive manner].

1. [Check for empty tree]

If T = NULL
then write (“Empty Tree”)
return.

2. [Process the left tree]

If LPTR(T) != NULL
then call RPOSTORDER(LPTR(T)).

3. [Process the right node]

If RPTR(T) != NULL
then call RPOSTORDER(RPTR(T)).

4. [Process the root node]

else
write DATA(T).

5. [FINISH]
return.

Share: 
 



Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: