Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct bst{
  6.     string nome;
  7.     bst* left;
  8.     bst* right;
  9.     bst* up;
  10.     bst* down;
  11.     bool isDirectory;
  12.  
  13.     void setRoot(){
  14.         this->nome = "/";
  15.         this->up = NULL;
  16.         this->down = NULL;
  17.         this->left = NULL;
  18.         this->right = NULL;
  19.         isDirectory = true;
  20.     }
  21. };
  22.  
  23. bst *touch(bst *root, bst* up, string nome){
  24.     if(root == NULL){
  25.         bst *n = new bst;
  26.         n->nome = nome;
  27.         n->left = NULL;
  28.         n->right = NULL;
  29.         n->down = NULL;
  30.         n->up = up;
  31.         n->isDirectory = false;
  32.         return n;
  33.     }else if(nome < root->nome){
  34.         root->left = touch(root->left, up,nome);
  35.         return root;
  36.     }else{
  37.         root->right = touch(root->right,up,nome);
  38.         return root;
  39.     }
  40. }
  41.  
  42. bst *mkdir(bst *root, bst* up, string nome){
  43.     if(root == NULL){
  44.         bst *n = new bst;
  45.         n->nome = nome;
  46.         n->left = NULL;
  47.         n->right = NULL;
  48.         n->down = NULL;
  49.         n->up = up;
  50.         n->isDirectory = true;
  51.         return n;
  52.     }else if(nome < root->nome){
  53.         root->left = touch(root->left, up,nome);
  54.         return root;
  55.     }else{
  56.         root->right = touch(root->right,up,nome);
  57.         return root;
  58.     }
  59. }
  60.  
  61. string pwd(bst *root){
  62.     return root->nome;
  63. }
  64.  
  65. string pre_order(bst* root, string indentacao){
  66.     if(root == NULL || root->up == NULL){
  67.         return "";
  68.     }else if(root->isDirectory){
  69.         indentacao += "    ";
  70.         return pre_order(root->down, indentacao);
  71.     }
  72.     cout << indentacao << root->nome << endl;
  73.     pre_order(root->left,indentacao);
  74.     pre_order(root->right,indentacao);
  75. }
  76.  
  77. string in_order(bst* root, string indentacao){
  78.     if(root == NULL || root->up == NULL){
  79.         return "";
  80.     }else if(root->isDirectory ){
  81.         indentacao += "    ";
  82.         return in_order(root->down, indentacao);
  83.     }
  84.     in_order(root->left,indentacao);
  85.     cout << indentacao << root->nome << endl;
  86.     in_order(root->right,indentacao);
  87. }
  88.  
  89. string pos_order(bst* root, string indentacao){
  90.     if(root == NULL || root->up == NULL){
  91.         return "";
  92.     }else if(root->isDirectory){
  93.         indentacao += "    ";
  94.         return pos_order(root->down, indentacao);
  95.     }
  96.     pos_order(root->left,indentacao);
  97.     pos_order(root->right,indentacao);
  98.     cout << indentacao << root->nome << endl;
  99. }
  100.  
  101. string ls(bst* root){
  102.     if(root == NULL || root->up == NULL){
  103.         return "";
  104.     }
  105.     ls(root->left);
  106.     cout << root->nome << endl;
  107.     ls(root->right);
  108. }
  109.  
  110.  
  111. int main(){
  112.     bst *pimba = new bst;
  113.     string indentacao = "";
  114.  
  115.     pimba->setRoot();
  116.  
  117.     pimba->down = touch(pimba->down, pimba, "E");
  118.     pimba->down = touch(pimba->down, pimba, "D");
  119.     pimba->down = touch(pimba->down, pimba, "B");
  120.     pimba->down = touch(pimba->down, pimba, "A");
  121.     pimba->down = touch(pimba->down, pimba, "C");
  122.     pimba->down = touch(pimba->down, pimba, "F");
  123.     cout << pwd(pimba) << endl;
  124.     ls(pimba->down);
  125.  
  126. //    bst *current;
  127. //
  128. //    string comando;
  129. //    string d;
  130. //
  131. //    while(cin >> comando){
  132. //        if(comando.compare("cd")){
  133. //            cin >> d;
  134. //
  135. //            if(d.compare("..")){
  136. //
  137. //            }
  138. //
  139. //        }else if(comando.compare("ls")){
  140. //
  141. //        }else if(comando.compare("touch")){
  142. //            string f;
  143. //            cin >> f;
  144. //
  145. //        }else if(comando.compare("mkdir")){
  146. //            string nD;
  147. //            cin >> nD;
  148. //
  149. //        }else if(comando.compare("pwd")){
  150. //            cout << pwd(current) << endl;
  151. //            }
  152. //
  153. //        }else if(comando.compare("tree")){
  154. //            string arg;
  155. //            cin >> arg;
  156. //            if(arg.compare("--pre-order")){
  157. //
  158. //            }else if(arg.compare("--in-order")){
  159. //
  160. //            }else if(arg.compare("--post-order")){
  161. //
  162. //            }else{
  163. //                cout << "Illegal option" << endl;
  164. //            }
  165. //
  166. //        }else if(comando.compare("rm")){
  167. //            string f;
  168. //            cin >> f;
  169. //
  170. //        }
  171. //    }
  172.  
  173.     return 0;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement