I’ve been told that the java class TreeMap uses an implementation of a RB tree. If this is the case, how does one do an inorder, preorder and postorder tree-walk on a TreeMap?
Or is this not possible?
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.
You wouldn’t be able to do this with the TreeMap implemented in the Collections library. Here’s an implementation of a Red-Black Tree in Java that you can look at though. Check out the
printTree()methods to see how they walk the tree in sorted order.From that maybe you can write your own methods to traverse the tree in all three orders.