π Background Information
The tree
command is a utility that prints out the structure of files and folders starting from a given folder (robinharwood et al., 2023). For example, if I use the tree
command from some folder on my disk, I might see the following:
$ tree path/to/folder/
path/to/folder/
βββ some-file.txt
βββ another-file.txt
βββ subfolder
β βββ my-code.cpp
β βββ my-code.h
βββ last-file.txt
1 directories, 5 files
The tree
command treats the files and folders on your disk as a tree data structure. The name of the command makes sense!
A robust implementation of tree
can be a bit complicated, but a GitHub user named Kevin Newton implements a simplified version of tree
whenever they want to learn a new programming language (Newton, 2025). We will analyze and expand upon their code in this lab.
π― Problem Statement
Complete the following tasks:
- Read through the C++ or Java implementation of the tree function as written by Newton in their tree repository (Newton, 2025).
- Make sure that you can run Newtonβs original code locally on your computer.
- Update the implementation of tree to list the directories / files in reverse alphabetical order.
β Acceptance Criteria
- The tree function should work in exactly the same way as before. However, the output should be different.
- Child directories should be listed in reverse alphabetical order.
- Files within each directory should be listed in reverse alphabetical order.
π Dev Notes
N/A
π₯οΈ Example Output
Suppose the original tree function listed files and directories like so:
$ ./tree.out
.
|- folder_a/
|---- file_a.txt
|---- file_b.txt
|---- file_c.txt
|- folder_b/
|---- file_a.txt
|---- file_b.txt
|---- file_c.txt
I now expect to see the following output:
$ ./tree.out
.
|- folder_b/
|---- file_c.txt
|---- file_b.txt
|---- file_a.txt
|- folder_a/
|---- file_c.txt
|---- file_b.txt
|---- file_a.txt
π Thought Provoking Questions
- How does the command work? Give a high-level description of how the command displays a tree in the console.
- Is the filesystem displayed by the
tree
command an example of a binary tree or a general tree? - What is the root node of the tree displayed by the
tree
command? - What are the leaf nodes of the tree displayed by the
tree
command? - How might you generate a tree with the largest possible depth via the
tree
command on a given filesystem?
πΌ Add-Ons For the Portfolio
N/A