How will you implement a tree structure in C for navigation in preorder depth-first manner?
How will you implement a tree structure in C for navigation in preorder depth-first
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A tree can be represented by two arrays: one that holds pre-order traversal and the second hold in-order traversal. This thread discusses [among other things] how it can be done.
Since array traversal is usually faster then tree traversal [due to cache performance mainly], you can represent the tree as 2 arrays, and use the pre-order traversal one to iterate.