Friday 26 July 2019

Couldn't solve coding challenge - advice on how to solve

Hey guys,I recently receive a coding challenge that I wasn't able to complete successfully and have been trying to understand what I was unable to code.I will include my code as well as the challenge.Challenge:The problemA common method of organizing files on a computer is to store them in hierarchical directories. For instance:photos/ birthdays/ joe/ Mary/vacations/weddings/In this challenge, you will implement commands that allow a user to create, move and delete directories.A successful solution will take the following input:CREATE fruitsCREATE vegetablesCREATE grainsCREATE fruits/applesCREATE fruits/apples/fujiLISTCREATE grains/squashMOVE grains/squash vegetablesCREATE foodsMOVE grains foodsMOVE fruits foodsMOVE vegetables foodsLISTDELETE fruits/applesDELETE foods/fruits/applesLISTand produce the following outputCREATE fruitsCREATE vegetablesCREATE grainsCREATE fruits/applesCREATE fruits/apples/fujiLISTfruitsapplesfuji grainsvegetablesCREATE grains/squashMOVE grains/squash vegetablesCREATE foodsMOVE grains foodsMOVE fruits foodsMOVE vegetables foodsLISTfoodsfruitsapples fuji grainsvegetablessquashDELETE fruits/applesCannot delete fruits/apples - fruits does not existDELETE foods/fruits/applesLISTfoodsfruitsgrainsvegetablessquash my code: https://pastebin.com/inn36dAZThe most glaring issue is that I was unable to find a way to parse the directories and create the tree in the directory dynamically so I hard coded some if statementsThank you for your help! it is appreciated

Submitted July 27, 2019 at 12:38AM by niirvana

No comments:

Post a Comment