|
Bill Teter email: william.teter@plattsburgh.edu |
|
|
lab 11 binary trees and a file system The object of this lab is to build a Linux like file navigation system. A file system is a general tree where a node may have any number of children. You will implement the navigation system on a binary tree class using the left-child next-sibling strategy. Your first step is to build a generic binary tree class following the suggestions in our text for the linked implementation. Then you will write a FileManager class that supports the following Linux commands (methods): There should be a constructor for FileManager that accepts a string and makes a directory with that name as the root of the file system. cd will make the root the current working directory ls will list the files in the current directory cd x will make x the current directory. We will assume that x is a child directory in the current directory touch x will create a file in the current directory called x mkdir x will create a subdirectory in the current directory called x. You can assume that the client never makes a mistake. Thus mkdir and touch are really the same. Further, you can assume that no two files or directories have the same name. Step 1 Create the generic binary tree class. In the public directory for lab11 are two files: BinaryTree.java and FileManagerTest.java. I have included in BinaryTree.java the headers for the methods I think you will need to do this project. I have placed the Node class as an inner class to simplify node access. The code for all these methods is in our text as are the specifications for all the method. Read the specifications and fill in the code for each method. You should test this class so that you are confident that everything works and that you understand the specs for each method. I suggest you create the following tree and then use get() to print each node. Make sure your find() method works. It is the most complicated. a b c
Step 2 Create a FileManager class Study my FileManagerTest program. If you create five methods in this class each corresponding to the five linux commands above, then you can use this test program to develop your code. In order to get ls to work you will have to move the cursor around in the binary tree to find all the file names. Once you have built the string of all the file names in the directory you will need to reset the cursor to where it was prior to the call ls. To do this you can save the the name of the current directory and then restore the cursor by using the find() method. Make sure you understand how to map a general tree onto a binary tree. I suggest you get touch and ls working first. Extra credit: Allow multiple files and or directories (that are not in the same directory) to have the same name. Print error messages like linux does for invalid operations like cd x if x is not a subdirectory. If a user enters an impossible command your system should print an error message and not change the state of your file manager system. |