When I write a code to search file in a directory recursively, for example I apply the method below:
public void list(File file) {
System.out.println(file.getName());
File[] children = file.listFiles();
for (File child : children) {
list(child);
}
}
If I need to show it in pre-order, in-order and post-order traversal, How can I do it?
I am not able to related tree traversal with this file search.
Your code is in pre-order, because the parent is processed (printed) before the children. If you moved the print to after the loop, it would be post-order. In-order would not make too much sense in this case. If you had a binary tree, it would be if you processed the parent in-between processing each child.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With