Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WindowsExplorer {
- public static void main(String[] args) throws Exception {
- int i,j,k;
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int N = Integer.parseInt(br.readLine());
- String commands[] = new String[N];
- for (i=0;i<N;i++)
- commands[i] = br.readLine();
- br.close();
- SLLTree<String> tree = new SLLTree<String>();
- tree.makeRoot("c:");
- SLLNode<String> current = tree.root;
- for (String command : commands) {
- if (command.contains(" ")) {
- String[] parts = command.split(" ");
- command = parts[0];
- if (command.equals("CREATE")) {
- tree.addChild(current, parts[1]);
- }
- if (command.equals("OPEN")) {
- SLLNode<String> tmp = current.firstChild;
- while (!tmp.equals(parts[1])) {
- tmp = tmp.sibling;
- }
- current = tmp;
- }
- if (command.equals("DELETE")) {
- SLLNode<String> tmp = current.firstChild;
- while (!tmp.equals(parts[1])) {
- tmp = tmp.sibling;
- }
- tree.remove(tmp);
- }
- } else {
- if (command.equals("PRINT")) {
- tree.printTree();
- }
- if (command.equals("BACK")) {
- current = current.parent;
- }
- if (command.equals("PATH")) {
- SLLNode<String> tmp = current;
- while (!tmp.equals(tree.root)) {
- System.out.print("\\" + tmp);
- tmp = tmp.parent;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement