Answered step by step
Verified Expert Solution
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
makeDirstring 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: ms memory limit: M
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 times.
fileName, dirName, name contain only lowercase letters, and the length range is
pathName only contains lowercase letters and pathName.length 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 functionmethod prototype including return value and the output is completed by the framework the first line
fixed output null
Example:
Input sample :
FileSystem
makeDirdirc
makeDirdirb
makeDirdirc
listDir
changeDirdirc
createFilefileb
makeDirdirb
createFiledirb
listDir
changeDirdirbdirc
Output sample :
null
true
true
false
dirbdirc
true
true
true
false
dirbfileb
false
Tip sample :
FileSystemnull
makeDirdirctrue
makeDirdirbtrue
makeDirdircfalse repeat
listDirdirb "dirc" note: do not add extra at the end of the directory name
changeDirdirctrue with a at the end, which is equivalent to the directory dirc
createFilefilebtrue
makeDirdirbtrue
createFiledirbfalse repeat
listDirdirb"fileb"
changeDirdirbdircfalse the directory does not exist
Input sample :
FileSystem
listDir
changeDir
createFilegateway
makeDirhome
changeDirgateway
makeDiretc
lisrDir
removegateway
changeDiretc
createFilepip
changeDiretc
lisrDir
changeDir
removeetc
listDir
Output sample :
null
true
true
true
false
true
etchomegateway
true
true
true
true
pip
true
true
home
Tip sample :
FileSystem
listDirThe query content at this time is
changeDir pathName is the current directory remains unchanged, returns true
changeDirgatewayThe file gateway exists in the current directory, but it is not a directory, so switch the directory
Recording failed.
makeDiretc
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.
removeetc 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 FileSystemMakeDirsysdirName;
bool param FileSystemCreateFilesysfileName;
bool param FileSystemChangeDirsyspathName;
bool param FileSystemRemovesysname;
char param FileSystemListDirsys&returnValSize;
FileSystemFreesys;
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,
compare the ASCII code values of a b cz 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,
and then the shorter one is ranked first.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started