资源管理器(数据结构)

资源管理器(数据结构)

ID:40008669

大小:47.00 KB

页数:9页

时间:2019-07-17

资源管理器(数据结构)_第1页
资源管理器(数据结构)_第2页
资源管理器(数据结构)_第3页
资源管理器(数据结构)_第4页
资源管理器(数据结构)_第5页
资源描述:

《资源管理器(数据结构)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、//模拟资源管理器#include#include#include#include#definemax100typedefstructTree{chardata[10];structTreechild,brother;}CsTree,Tnode;typedefstruct{chardata[max][10];inttop;}seqstack;intpushstack(seqstack&s,charch){if(s.top==max-1){printf

2、("栈满!");return0;}s.top++;strcpy(s.data[s.top],ch);return1;}voidpopstack(seqstack&s){if(s.top==-1){printf("栈空!");return;}elses.top--;}voidprintstack(seqstacks){inti=0;if(s.top==-1){printf("栈空!");return;}while(i<=s.top){printf("%s",s.data[i]);i++;}printf("");

3、}//创建树voidcreate(CsTree&T){charstr[20];scanf("%s",str);if(strcmp(str,"#")==0)T=NULL;else{T=(Tnode)malloc(sizeof(Tnode));strcpy(T->data,str);create(T->child);create(T->brother);}}//先序遍历voidpreorder(CsTreeT){if(T){printf("%s",T->data);preorder(T->child);preorder(T->b

4、rother);}}//销毁树voiddestroy(CsTree&T){if(T==NULL)return;if(T->child)destroy(T->child);if(T->brother)destroy(T->brother);free(T);T=NULL;}//凹入显示1voidprint(CsTreeT,intindent){inti;if(T==NULL)return;else{for(i=0;idata);print(T->

5、child,indent+1);print(T->brother,indent);//兄弟节点不需再缩进}}//由给定节点信息查找并返回其指针voidfind(CsTreeT,charpdata,CsTree&pfind){if(T==NULL)return;else{if(strcmp(T->data,pdata)==0)pfind=T;else{find(T->child,pdata,pfind);find(T->brother,pdata,pfind);}}}//由给点节点信息查找并返回其指针和其父节点指针voidfi

6、ndparent(CsTreeT,charpdata,CsTreep,CsTree&pfind,CsTree&parent){if(T==NULL)return;else{if(strcmp(T->data,pdata)==0){pfind=T;parent=p;return;}else{p=T;//暂存上一级节点findparent(T->child,pdata,p,pfind,parent);p=T;findparent(T->brother,pdata,p,pfind,parent);}}}//插入voidinsert

7、(CsTreeT,charpdata,charnewdata){CsTreepfind=NULL,pnew=NULL,pchild=NULL;find(T,pdata,pfind);if(pfind==NULL){printf("所找节点不存在!");return;}else{find(pfind,newdata,pchild);if(pchild){printf("所找节点已存在!");return;}else{pnew=(Tnode)malloc(sizeof(Tnode));if(pnew==NULL)exit

8、(0);strcpy(pnew->data,newdata);if(pfind->child){pnew->brother=pfind->child;pnew->child=NULL;}else{pnew->child=NULL;pnew->brother=NULL;}pfind->chi

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。