阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数getword(char*filename,char*word)是从指定的文件中得到单词。char*strdup(char*S)是复制S所指向的字符串,并返回复制字符串的地址。[C程序]include <stdio.h>include <ctype.h>include <string.h>define MAXWORD 100struct 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);}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明]

本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数getword(char*filename,char*word)是从指定的文件中得到单词。char*strdup(char*S)是复制S所指向的字符串,并返回复制字符串的地址。

[C程序]

include <stdio.h>

include <ctype.h>

include <string.h>

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);

}


相关考题:

●试题四阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】函数QuickSort是在一维数组A[n]上进行快速排序的递归算法。【函数】void QuickSort(int A[],int s,int t){int i=s,j=t+1,temp;int x=A[s];do{do i++;while (1) ;do j--;while(A[j]x);if(ij){temp=A[i]; (2) ; (3) ;}}while(ij);A[a]=A[j];A[j]=x;if(si-1) (4) ;if(j+1t) (5) ;}

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]完成以下中序线索化二叉树的算法。[函数]Typedef int datatype;Typedef struct node {Int ltag, rtag;Datatype data;*lchild,* rchild;}bithptr;bithptr pre;void inthread ( p );{if{inthread ( p->lchild );if ( p->lchild==unll ) (1);if ( P->RCHILD=NULL) p->rtag=1;if (2){if (3) pre->rchild=p;if ( p->1tag==1 )(4);}INTHREAD ( P->RCHILD );(5);}}

阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。【说明】在下面函数横线处填上适当的字句,使其输出结果为:构造函数.构造函数.1,25,6析构函数析构函数.【C++代码】include "iostream.h"class AA{ public;AA(int i,int j){A=i; B=j;cout<<"构造函数.\n";}~AA(){(1);}void print();private:int A, B;};void AA∷print(){cout<<A<<","<<B<<endl;}void main(){AA *a1, *a2;(2)=new AA(1, 2);a2=new AA(5, 6);(3);a2->print();(4) a1;(5) a2;}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在答题纸的对应栏内。【函数2.1说明】递归函数sum(int a[], int n)的返回值是数组a[]的前n个元素之和。【函数2.1】int sum (int a[],int n){if(n>0) return (1);else (2);}【函数2.2说明】有3个整数,设计函数compare(int a,int b,int c)求其中最大的数。【函数2.2】int compare (int a, int b, int c ){ int temp, max;(3) a:b;(4) temp:c;}【函数2.3说明】递归函数dec(int a[],int n)判断数组a[]的前n个元素是否是不递增的。不递增返回 1,否则返回0。【函数2.3】int dec( int a[], int n ){if(n<=1) return 1;if(a[0]<a[1]) return 0;return (5);}

阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是计算x和y的最小公倍数。[函数2.1]main(){ int m,n,d,r;seanf("%d %d",m,n);if(m<n) {r=m;m=n;n=r;}(1);while (d%n! =0) (2);printf("%d\n",d);}[函数2.2说明]下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。[函数2.2]include <stdio.h>main(){ char c,preChar='\0';c = getchar();while(c! = '.'){if((3)) putchar(c);else if(preChar! =' ') putchar(c);(4);c=(5);}}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]已知r[1...n]是n个记录的递增有序表,用折半查找法查找关键字为k的记录。若查找失败,则输出“failure",函数返回值为0;否则输出“success”,函数返回值为该记录的序号值。[C函数]int binary search(struct recordtype r[],int n,keytype k){ intmid,low=1,hig=n;while(low<=hig){mid=(1);if(k<r[mid].key) (2);else if(k==r[mid].key){printf("succesS\n");(3);}else (4);}printf("failure\n");(5);}

●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。