赞
踩
#include<STDIO.H> #include<STRING.H> #include<MALLOC.H> #include<MATH.H> struct Ttree { char data[20]; double weight; double num; //一篇文献中的某一索引词出现的次数 double max; //一篇文献的总字数 double n; //索引词出现在几个文档中 struct Ttree *lchild; //左儿子 struct Ttree *rchild; //右儿子 }; struct Ttree *rootW=NULL; double MF=6; FILE *fp=fopen("D://mm.txt","w"); Ttree *createTtree(Ttree *root,FILE *fp){ int i=0,t=0; struct Ttree *p,*q; //定义中间指针变量 char ch; p=(Ttree*)malloc(sizeof(Ttree)); //申请新的存储空间 p->data[0]='/0'; if(fp==NULL) { printf("/nCannot open file strike any key exit!"); return NULL; } ch=fgetc(fp); while((ch!=EOF)&&(t==0)) { if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){ if(ch<='Z') ch=ch+32; p->data[i]=ch; i++; } else{ if(p->data[0]=='/0'){ch=fgetc(fp);continue;} p->data[i]='/0'; p->max++; p->n=1; p->num=1; i=0; t=1; p->lchild=NULL; p->rchild=NULL; //初始化头节点的左右儿子为空指针 root=p; } ch=fgetc(fp); } q=(Ttree*)malloc(sizeof(Ttree)); q->data[0]='/0' ; while(ch!=EOF){ if((ch>='a'&&ch<='z')||(ch>=