Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct bst{
- string nome;
- bst* left;
- bst* right;
- bst* up;
- bst* down;
- bool isDirectory;
- void setRoot(){
- this->nome = "/";
- this->up = NULL;
- this->down = NULL;
- this->left = NULL;
- this->right = NULL;
- isDirectory = true;
- }
- };
- bst *touch(bst *root, bst* up, string nome){
- if(root == NULL){
- bst *n = new bst;
- n->nome = nome;
- n->left = NULL;
- n->right = NULL;
- n->down = NULL;
- n->up = up;
- n->isDirectory = false;
- return n;
- }else if(nome < root->nome){
- root->left = touch(root->left, up,nome);
- return root;
- }else{
- root->right = touch(root->right,up,nome);
- return root;
- }
- }
- bst *mkdir(bst *root, bst* up, string nome){
- if(root == NULL){
- bst *n = new bst;
- n->nome = nome;
- n->left = NULL;
- n->right = NULL;
- n->down = NULL;
- n->up = up;
- n->isDirectory = true;
- return n;
- }else if(nome < root->nome){
- root->left = touch(root->left, up,nome);
- return root;
- }else{
- root->right = touch(root->right,up,nome);
- return root;
- }
- }
- string pwd(bst *root){
- return root->nome;
- }
- string pre_order(bst* root, string indentacao){
- if(root == NULL || root->up == NULL){
- return "";
- }else if(root->isDirectory){
- indentacao += " ";
- return pre_order(root->down, indentacao);
- }
- cout << indentacao << root->nome << endl;
- pre_order(root->left,indentacao);
- pre_order(root->right,indentacao);
- }
- string in_order(bst* root, string indentacao){
- if(root == NULL || root->up == NULL){
- return "";
- }else if(root->isDirectory ){
- indentacao += " ";
- return in_order(root->down, indentacao);
- }
- in_order(root->left,indentacao);
- cout << indentacao << root->nome << endl;
- in_order(root->right,indentacao);
- }
- string pos_order(bst* root, string indentacao){
- if(root == NULL || root->up == NULL){
- return "";
- }else if(root->isDirectory){
- indentacao += " ";
- return pos_order(root->down, indentacao);
- }
- pos_order(root->left,indentacao);
- pos_order(root->right,indentacao);
- cout << indentacao << root->nome << endl;
- }
- string ls(bst* root){
- if(root == NULL || root->up == NULL){
- return "";
- }
- ls(root->left);
- cout << root->nome << endl;
- ls(root->right);
- }
- int main(){
- bst *pimba = new bst;
- string indentacao = "";
- pimba->setRoot();
- pimba->down = touch(pimba->down, pimba, "E");
- pimba->down = touch(pimba->down, pimba, "D");
- pimba->down = touch(pimba->down, pimba, "B");
- pimba->down = touch(pimba->down, pimba, "A");
- pimba->down = touch(pimba->down, pimba, "C");
- pimba->down = touch(pimba->down, pimba, "F");
- cout << pwd(pimba) << endl;
- ls(pimba->down);
- // bst *current;
- //
- // string comando;
- // string d;
- //
- // while(cin >> comando){
- // if(comando.compare("cd")){
- // cin >> d;
- //
- // if(d.compare("..")){
- //
- // }
- //
- // }else if(comando.compare("ls")){
- //
- // }else if(comando.compare("touch")){
- // string f;
- // cin >> f;
- //
- // }else if(comando.compare("mkdir")){
- // string nD;
- // cin >> nD;
- //
- // }else if(comando.compare("pwd")){
- // cout << pwd(current) << endl;
- // }
- //
- // }else if(comando.compare("tree")){
- // string arg;
- // cin >> arg;
- // if(arg.compare("--pre-order")){
- //
- // }else if(arg.compare("--in-order")){
- //
- // }else if(arg.compare("--post-order")){
- //
- // }else{
- // cout << "Illegal option" << endl;
- // }
- //
- // }else if(comando.compare("rm")){
- // string f;
- // cin >> f;
- //
- // }
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement