Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java pls I'll upvote: Please simulate and implement a simple file system FileSystem ( ) : System initialization, currently in the directory / ,

Use Java pls I'll upvote:
Please simulate and implement a simple file system
FileSystem(): System initialization, currently in the directory /, the root directory is empty
makeDir(string dirName): Create a new directory in the current directory, if the directory name dirName is the same as the current directory
If the file or directory name in the previous directory is repeated, the creation fails and false is returned. Otherwise, the creation is successful and true.
createFile (string filename): Create a new file in the current directory, if the file name fileName and
If the file name or directory name in the current directory is repeated, the creation will fail and return false, else true
change Dir (string pathname) switches the current directory to pathName: First, if pathName is "",
The current directory remains unchanged and returns true; if the directory exists, the switch returns true, otherwise false
remove (string name) deletes the file or directory named name in the current directory: if it exists, delete it.
Function, true, otherwise false is returned directly (deleting a directory requires recursively deleting all files in the directory)
listDir: Returns the directories and files in the current directory, with the directories in front and files in the back, in dictionary order.
(The returned results do not include content in subdirectories) Sort by ascii
answer requests
Time limit: 1000ms, memory limit: 256M
Input
Each line represents a function call. The initialization function is only called once in the first line, and the cumulative function calls do not exceed 1,000 times.
fileName, dirName, name contain only lowercase letters, and the length range is [1,100]
pathName only contains lowercase letters and /,0<= pathName.length <1000, Note: does not contain .. or .
Note: When pathName is not "", it is a legal directory name, and may have a / at the end.
output
When answering questions, implement it according to the requirements in the function/method prototype (including return value), and the output is completed by the framework (the first line
fixed output null)
Example:
Input sample 1:
FileSystem()
makeDir(dirc)
makeDir(dirb)
makeDir(dirc)
listDir()
changeDir(dirc/)
createFile(fileb)
makeDir(dirb)
createFile(dirb)
listDir()
changeDir(/dirb/dirc)
Output sample 1:
null
true
true
false
[dirb,dirc]
true
true
true
false
[dirb,fileb]
false
Tip sample 1:
FileSystem()//null
makeDir("dirc")//true
makeDir("dirb")//true
makeDir("dirc")//false, repeat
listDir()//["dirb", "dirc"], note: do not add extra / at the end of the directory name
changeDir("dirc/")//true, with a / at the end, which is equivalent to the directory dirc
createFile("fileb")//true
makeDir("dirb")//true
createFile("dirb")//false, repeat
listDir()//["dirb","fileb"]
changeDir("/dirb/dirc")//false, the directory does not exist
Input sample 2:
FileSystem()
listDir()
changeDir()
createFile(gateway)
makeDir(home)
changeDir(gateway)
makeDir(etc)
lisrDir()
remove(gateway)
changeDir(etc/)
createFile(pip)
changeDir(/etc/)
lisrDir()
changeDir(/)
remove(etc)
listDir()
Output sample 2:
null
[]
true
true
true
false
true
[etc,home,gateway]
true
true
true
true
[pip]
true
true
[home]
Tip sample 2:
FileSystem()
listDir()//The query content at this time is []
changeDir("")// pathName is "", the current directory remains unchanged, returns true
...
changeDir("gateway")//The file gateway exists in the current directory, but it is not a directory, so switch the directory
Recording failed.
makeDir("etc")
listDir()// When returning, the directories home and etc are at the front, and the file gateway is at the back; the directories are etc in ascending dictionary order.
and home.
...
remove("etc")// Currently in the root directory, delete the directory etc under it, and all subdirectories and files under etc
...
Tips:
// Initialization and calling reference (take C as an example, refer to other languages):
FileSystem *sys = FileSystemCreate();
bool param_1= FileSystemMakeDir(sys,dirName);
bool param_2= FileSystemCreateFile(sys,fileName);
bool param_3= FileSystemChangeDir(sys,pathName);
bool param_4= FileSystemRemove(sys,name);
char **param_5= FileSystemListDir(sys,&returnValSize);
FileSystemFree(sys);
Dictionary order: refers to a method of sorting words according to the order in which they appear in the dictionary. First, according to the first character, 0,1,
2...9, compare the ASCII code values of a, b, c...z, etc., and the smaller one will be ranked first; if the first character is the same, then compare the first character
The second, third and even subsequent characters. If the last two words are not the same length (such as sigh and sight, 0312
and 03121), then the shorter one is ranked first.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions