Logo 
Search:

C++ Programming FAQ

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

Write an algorithm for Creating a Binary Tree in dfs (data file structure).

  Shared By: Noah Bouchard    Date: Oct 02    Category: C++ Programming    Views: 2392

Answer:

PROCEDURE CREATE(ROOT)

1. [Initialize]

ROOT <-- NODE
LPTR(ROOT) <-- NULL
RPTR(ROOT) <-- NULL
CALL PUSH(Q,R,ROOT)
READ (DATA(ROOT)).

2. [Process the input]

Repeat thru step 4 while f>=0.

3. [Creating left child]

D <-- CALL POP(Q,F)
LPTR(D) <-- NODE
LPTR(LPTR(D)) <-- NULL
RPTR(LPTR(D)) <-- NULL
CALL PUSH(Q,R,LPTR(D))
READ(DATA(LPTR(D))).

4. [Creating right child]

D <-- CALL POP(Q,F)
RPTR(D) <-- NODE
LPTR(RPTR(D)) <-- NULL
RPTR(RPTR(D)) <-- NULL
CALL PUSH(Q,R,RPTR(D))
READ(DATA(RPTR(D))).

5. [FINISH]
return.

Share: 
 


Related Topics:

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


Tagged: