2011_3华中科技大学机试真题
来源:互联网 发布:一个c语言源程序是由 编辑:程序博客网 时间:2024/04/30 12:06
#include<stdio.h>#include<malloc.h>#include<string.h>typedef struct BiNode{char *s;struct BiNode *lchild;struct BiNode *rchild;}BiNode,*BiTree;void PreOrder(BiTree T){if(T){printf("%s\n",T->s);PreOrder(T->lchild);PreOrder(T->rchild);}}int main(){char **str,e;int row=1,col=1;int tag,i,len;BiTree T,r,t;str=(char **)malloc(row*sizeof(char *));str[col-1]=(char *)malloc(col*sizeof(char));tag=1;while((e=getchar())!='\n'){if(e==' '){str[row-1][col-1]='\0';tag=0;continue;}else{if(tag==0){row++;col=2;str=(char **)realloc(str,row*sizeof(char *));str[row-1]=(char *)malloc(col*sizeof(char));str[row-1][col-2]=e;tag=1;}else{col++;str[row-1]=(char *)realloc(str[row-1],col*sizeof(char));str[row-1][col-2]=e;}}}str[row-1][col-1]='\0';for(i=0;i<row;i++)printf("%s\n",str[i]);printf("\n");len=strlen(str[0]);T=(BiTree)malloc(sizeof(BiNode));T->s=(char *)malloc((len+1)*sizeof(char));strcpy(T->s,str[0]);T->lchild=T->rchild=NULL;t=T;for(i=1;i<row;i++){len=strlen(str[i]);r=(BiTree)malloc(sizeof(BiNode));r->s=(char *)malloc((len+1)*sizeof(char));r->lchild=NULL;r->rchild=NULL;strcpy(r->s,str[i]);while(t){if(strcmp(t->s,r->s)>0){if(t->lchild)t=t->lchild;else{t->lchild=r;break;}}else{if(t->rchild)t=t->rchild;else{t->rchild=r;break;}}}t=T;}PreOrder(T);return 0;}
0 0
- 2011_3华中科技大学机试真题
- 2011_1华中科技大学机试真题
- 2011_2华中科技大学机试真题
- 2012_1华中科技大学机试真题
- 2012_2华中科技大学机试真题
- 2011华中科技大学研究生复试机试之一
- 2011华中科技大学研究生复试机试之二
- 2011华中科技大学研究生复试机试之三
- 2011级华中科技大学软件学院软件工程硕士培养方案(附课表)
- 华中科技大学的IP
- 华中科技大学社会系
- CentOS5华中科技大学更新源
- 06华中科技大学复试上机
- 华中科技大学IPV6设置,linux
- 华中科技大学海外校友录
- 华中科技大学网络教材
- 黑晓军 华中科技大学 博士 副教授
- 华中科技大学软件工程硕士
- 2011_2华中科技大学机试真题
- python学习笔记-(3)序列-Sequence
- HDU ACM 2206 IP的计算
- 有关Grails的事务
- Merge讲解与实例
- 2011_3华中科技大学机试真题
- OPENSSH - Build a backdoor
- ORACLE批量更新四种方法比较
- MAC 恢复jdk1.6
- linux下ActiveMQ启动异常UNKnowHost
- 字符串的应用2
- PHP内核分析(一)
- android 获取手机网络状态
- iOS UIBezierPath类 介绍