Advertisement
nocturnalmk

Untitled

Nov 28th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. public class WindowsExplorer {
  2.    
  3.     public static void main(String[] args) throws Exception {
  4.         int i,j,k;
  5.        
  6.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  7.        
  8.         int N = Integer.parseInt(br.readLine());
  9.         String commands[] = new String[N];
  10.        
  11.         for (i=0;i<N;i++)
  12.             commands[i] = br.readLine();
  13.            
  14.         br.close();
  15.        
  16.         SLLTree<String> tree = new SLLTree<String>();
  17.         tree.makeRoot("c:");
  18.         SLLNode<String> current = tree.root;
  19.        
  20.         for (String command : commands) {
  21.            
  22.             if (command.contains(" ")) {
  23.                
  24.                 String[] parts = command.split(" ");
  25.                 command = parts[0];
  26.                
  27.                 if (command.equals("CREATE")) {
  28.                     tree.addChild(current, parts[1]);
  29.                 }
  30.                 if (command.equals("OPEN")) {
  31.                     SLLNode<String> tmp = current.firstChild;
  32.                     while (!tmp.equals(parts[1])) {
  33.                         tmp = tmp.sibling;
  34.                     }
  35.                     current = tmp;
  36.                 }
  37.                
  38.                 if (command.equals("DELETE")) {
  39.                     SLLNode<String> tmp = current.firstChild;
  40.                     while (!tmp.equals(parts[1])) {
  41.                         tmp = tmp.sibling;
  42.                     }
  43.                     tree.remove(tmp);
  44.                 }
  45.                
  46.             } else {
  47.                
  48.                 if (command.equals("PRINT")) {
  49.                     tree.printTree();
  50.                 }
  51.                
  52.                 if (command.equals("BACK")) {
  53.                     current = current.parent;              
  54.                 }
  55.                
  56.                 if (command.equals("PATH")) {
  57.                    
  58.                     SLLNode<String> tmp = current;
  59.                    
  60.                     while (!tmp.equals(tree.root)) {
  61.                         System.out.print("\\" + tmp);
  62.                         tmp = tmp.parent;
  63.                     }
  64.                    
  65.                    
  66.                 }
  67.  
  68.             }
  69.            
  70.            
  71.         }
  72.        
  73.        
  74.     }
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement