当前位置:计算机-软考初级

[问答题]阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内.
[说明]
本程序实现对指定文件内的单词进行计数.其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数.此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值.函数getword(char*filename,char*word)是从指定的文件中得到单词.char*strdup(char*S)是复制S所指向的字符串,并返回复制字符串的地址.
[C程序]
include
include
include
define MAXWORD 100
struct node {
char*word;
int count;
struct node*left;
struct node*right;
}
struct node*addtree(struct node*P,char*w)
{ int cond;
if(p==NULL){ /*向树中插入结点*/
P=(struct node*)malloc(sizeof(struct node));
P->word=strdup(w);
P->count=1;
(1) ;
}
elseif((oond=strcmp(w,p->word))==0) (2) ;
else if(cond<0)p->left=(3);
else p->right=(4);
return p;
}
main( )
{ Struct node*root;
char word[MAXWORD];
root=NULL;
filename="example.dat";
while(getword(filename,word)!=EOF))
root=(5);
}

相关题目

关于我们 | 网站声明 | 联系我们 | 违法和不良信息举报

Copyright © 2020 - 2022
石家庄晋咸软件科技有限公司  版权所有
冀ICP备2021011520号-1
冀公网安备 13012102000087号