未分类题

阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。
【说明】
本程序从正文文件text.in中读入一篇英文短文,统计该短文中不同单词及出现次数,并按词典编辑顺序将单词及出现次数输出到正文文件worD.out中。
程序用一棵有序二叉树存储这些单词及其出现的次数,边读入边建立,然后中序遍历该二叉树,将遍历经过的二叉树上的结点内容输出。
【函数】
include <stdio.h>
include <malloC.h>
include <ctypE.h>
include <string.h>
define INF 'text.in'
define OUTF 'worD.our'
typedef struct treenode {
char *word;
int count;
struct treenode *left, *right;
} BNODE;
int getword(FILE *fpt, char *word)
{ char c;
c=fgetc(tpt);
if (c==EOF)
return 0;
while(!(tolower(c)>= 'a' && tolower(c)<= 'z'))
{ c=fgetc(fpt);
if (c==EOF)
return 0;
} /* 跳过单词间的所有非字母字符 */
while(tolower(c)>= 'a' && tolower(c)<= 'z')
{ *word++=c;
c=fgetc(fpt);
}
*word='/0';
return 1;
}
void binary_tree(BNODE **t, char *word)
{ BNODE *ptr, *p; int compres;
p=NULL;
(1);
while (ptr) /* 寻找插入位置 */
{ compres=strcmp(word, ptr->word);/* 保存当前比较结果 */
if (!compres)
{ (2); return;}
else
{ p=ptr;
ptr=compres>0 ? ptr->right: ptr->left;
}
}
ptr=(BNODE *)malloc(sizeof(BNODE));
ptr->left=ptr->right=NULL;
ptr->word=(char *)malloc(strlen(word)+1);
strcpy(ptr->word, word);
(3);
if (p==NULL)
*t=ptr;
else if (compres>0)
p->right=ptr;
else
p->left=ptr;
}
void midorder(FILE *fpt, BNODE *t)
{ if (t==NULL)
return;
midorder(fpt,(4));
fprintf(fpt, '%s %d/n', t->word, t->count);
midorder(fpt, t->right);
}
void main()
{ FILE *fpt; char word[40];
BNODE *root=NULL;
if ((fpt=fopen(INF, 'r'))==NULL)
{ printf('Can't open file %s/n', INF);
return;
}
while(getword(fpt, word)==1)
binary_tree((5));
fclose(fpt);
fpt=fopen(OUTF, 'w');
if (fpt==NULL)
{ printf('Can't open fife %s/n', OUTF);
return;
}
midorder(fpt, root);
fclose(fpt);
}

A.in中读入一篇英文短文,统计该短文中不同单词及出现次数,并按词典编辑顺序将单词及出现次数输出到正文文件worD.out中。
B.h>
C.h>
D.h>
E.h>
F.in'
G.our'

【参考答案】

(1)ptr=*t (2)ptr->count++ (3)ptr->count=1(4)t->left (5)&root......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

未分类题
听力原文:TUTOR: Right. Are we all here? OK. As you know, today Vivien is going to do a 【Example】presentation on the hat-making project she did with her class during her lastteaching practicE.So, over to you, Vivien.VIVIEN: Thanks. Um... Mr Yardley has asked me to describe to you the project I did asa student teacher at a secondary school in London. I was at this school for six 【Q31】weeks and I taught a variety of subjects to a class of fourteen-year-old pupils. 【Q32】The project I chose to do was a hat-making project and I think this projectcould easily be adapted to suit any agE.So, to explain the project...After we'd done the research, we went back to the classroom to make twobasic hat shapes using rolls of old wallpaper. We each made, first of all, aconical hat by... er... if I show you now.., cutting out a circle and then 【Q33】making one cut up to the centre and then.., er... overlapping the cut like thisthis.., a conical hat that sits on your heaD.The other hat we made was a littlemore complicateD.., er... first of all we cut out a circle again.., like this...then you need a long piece with flaps on it - I've already made that bit which Ihave here - you bend the flaps over and stick them.., with glue or prittstick... 【Q34】to the underside of the circlE.., like this. Again, I've prepared this so that Idon't get glue everywherE.The pupils do, of course, so you need plenty of coversfor the tablE.And there you have a pillbox hat as in pill and box. Now variationsand combinations of these two hat shapes formed the basis of the pupils' finaldesigns.The next stage of the project was the design phase and this involved, first of all, 【Q35】using their pages of research to draw a design of their hat on paper. That's theeasy part. They then had to translate their two-dimensional design into a formto fit their heaD.I encouraged them to make a small-scale, three-dimensional 【Q36】hat first so that they could experiment with how to achieve the form. theyrequired and I imposed certain constraints on them to keep things simplE.Forexample, they had to use paper not carD.Paper is more pliable and easier tohandlE.They also had to limit their colours to white, grey or brown shades of 【Q37】paper which reflected the colours of the buildings they were using as a modelfor their hats and they had to make sure their glue didn't show!Well, it was very enjoyable and just to give you an idea of what theyproduced, I've brought along three hats to show you. This one here is based on 【Q38】a circular stairway in an old building in London. It uses three pillbox hats oneon top of the other. This was designed by TheresA.Here's another one that has 【Q39】&nbs
A.VIVIEN:
B...
C...
D...
E...
F..,
G..,
H...
I..,
J..,
K...
L..,
M...
N..,
O...
P..,
Q.