BUPT OJ 文件系统
来源:互联网 发布:心电图工作站软件下载 编辑:程序博客网 时间:2024/06/08 12:38
孩子兄弟表示法的多叉树遍历
#include<iostream>#include<string>using namespace std;enum type{file,dir};class node{public:string name;type mytype;node*child;node*brother;//孩子兄弟表示法; };void CreateFile(node*pt,string filename){node*temp=new node;temp->mytype=file;temp->child=temp->brother=NULL;temp->name=filename;if(pt->child!=NULL){ node* tempnode=pt->child;while(tempnode->brother!=NULL){tempnode=tempnode->brother;}tempnode->brother=temp;}else{pt->child=temp;}}void CreateDir(node*pt,string dirname){node*temp=new node;temp->mytype=dir;temp->child=temp->brother=NULL;temp->name=dirname;if(pt->child!=NULL){ node* tempnode=pt->child;while(tempnode->brother!=NULL){tempnode=tempnode->brother;}tempnode->brother=temp;}else{pt->child=temp;}}void ListFile(node*pt){node*now=pt->child;while(now){if(now->mytype==file){cout<<now->name<<endl;}now=now->brother;}}void ListDir(node*pt){node*now=pt->child;while(now){if(now->mytype==dir){cout<<now->name<<endl;}now=now->brother;}}node* travel(node*root,string name){if(root){if(root->name==name)return root;node*p=NULL;p=travel(root->child,name);if(p)return p;return travel(root->brother,name);}}int main(){int t,op;string task;cin>>t;node *root=new node;;root->name="root";root->mytype=dir;while(t--){root->child=root->brother=NULL;cin>>op;while(op--){cin>>task;if(task=="CREATEFILE"){string FILENAME,DIRNAME;cin>>FILENAME>>DIRNAME;node *fa=travel(root,DIRNAME);CreateFile(fa,FILENAME); }else if(task=="CREATEDIR"){string DIRNAME1,DIRNAME2;cin>> DIRNAME1 >> DIRNAME2;node *fa=travel(root,DIRNAME2);CreateDir(fa,DIRNAME1);}else if(task=="LISTFILE"){string DIRNAME;cin>>DIRNAME;node *fa=travel(root,DIRNAME);ListFile(fa);}else{string DIRNAME;cin>>DIRNAME;node *fa=travel(root,DIRNAME);ListDir(fa);}}}}
0 0
- BUPT OJ 文件系统
- BUPT OJ91 文件系统
- BUPT OJ 147. Substring
- BUPT OJ 矩阵幂
- BUPT OJ IP地址
- BUPT OJ 寻找宝藏
- BUPT OJ 虚数
- BUPT OJ 统计节点个数
- BUPT OJ 最小距离查询
- BUPT OJ 非平方等式
- BUPT OJ 96 矩阵幂
- BUPT OJ 101 IP地址
- BUPT OJ 中序遍历序列
- BUPT OJ 中序遍历树
- BUPT OJ 丁神又去谷歌
- bupt
- 91. 文件系统 code.bupt.edu.cn 题干问题
- dijkstra模板+ 缩点-bupt新oj-187- Find the Fastest Server
- vim快捷键总结
- 微信小程序之四(设置底部导航)
- Android 4.4 KitKat NotificationManagerService使用详解与原理分析(一)__使用详解
- 从Java SE的角度认识JavaBean
- 文章标题
- BUPT OJ 文件系统
- Python3 快速入门(一)
- windows下使用cpanm进行模块安装
- 2017.1.13【初中部 GDKOI】模拟赛B组 逆光 题解
- 画流程图的网站ProcessOn
- Linux利用yum下载rpm安装包
- 利用spring的线程池ThreadPoolTaskExecutor对多个库进行数据归档
- 图像处理中灰度变换方法总结
- JSTL_自定义标签