网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

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

【说明】

本程序利用非递归算法实现二叉树后序遍历。

【函数】

include<stdio.h>

include<stdlib.h>

typedef struct node{/*二叉树的结点数据结构类型*/

char data;

struct node *left;

struct node *right;

}BTREE;

void SortTreelnsert(BTREE **tree, BTREE *s)

{

if(*tree==NULL)*tree=s;

else

if(s->data<(*tree)->data)

SortTreelnsert((1),s);

else if(s->data>=(*tree)->data)

SortTreelnsert((2),s);

}

void TraversalTree(BTREE *tree)

{

BTREE *stack[1 000],*p;

int tag[1000],top=0;

p=tree;

do{

while(p !=NULL)

{

stack[++top]=p;

(3);

tag[top]=0; /*标记栈顶结点的左子树已进行过后序遍历*/

}

while(top>0&&(4))/*栈顶结点的右子树是否被后序遍历过*/

{

p=stack[top--];

putchar(p->data);

}

if(top>0)/*对栈顶结点的右子树进行后序遍历*/

{

(5);

tag[top]=1;

}

}while(top>0);

}

void PrintSortTree(BTREE *tree)

{

if(tree !=NULL)

{

printSortTree(tree->left);

putchar(tree->data);

pdntSortTree(tree->right);

}

}

main()

{

BTREE *root=NULL, *node;

char ch;

ch=getchar();

while(ch !='')

{

node=(BTREE*)malloc(sizeof(BTREE));

node->data=ch;

node->left=node->right=NULL;

SortTreelnsert(&root, node);

ch=getchar();

}

PrintSortTree(root);

putchar('\n');

TraversalTree(root);

}


参考答案

更多 “ 阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。【说明】本程序利用非递归算法实现二叉树后序遍历。【函数】include<stdio.h>include<stdlib.h>typedef struct node{/*二叉树的结点数据结构类型*/char data;struct node *left;struct node *right;}BTREE;void SortTreelnsert(BTREE **tree, BTREE *s){if(*tree==NULL)*tree=s;elseif(s->data<(*tree)->data)SortTreelnsert((1),s);else if(s->data>=(*tree)->data)SortTreelnsert((2),s);}void TraversalTree(BTREE *tree){BTREE *stack[1 000],*p;int tag[1000],top=0;p=tree;do{while(p !=NULL){stack[++top]=p;(3);tag[top]=0; /*标记栈顶结点的左子树已进行过后序遍历*/}while(top>0(4))/*栈顶结点的右子树是否被后序遍历过*/{p=stack[top--];putchar(p->data);}if(top>0)/*对栈顶结点的右子树进行后序遍历*/{(5);tag[top]=1;}}while(top>0);}void PrintSortTree(BTREE *tree){if(tree !=NULL){printSortTree(tree->left);putchar(tree->data);pdntSortTree(tree->right);}}main(){BTREE *root=NULL, *node;char ch;ch=getchar();while(ch !=''){node=(BTREE*)malloc(sizeof(BTREE));node->data=ch;node->left=node->right=NULL;SortTreelnsert(root, node);ch=getchar();}PrintSortTree(root);putchar('\n');TraversalTree(root);} ” 相关考题
考题 ●试题四阅读下列函数说明和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) ;}

考题 阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

考题 阅读下列函数说明和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(i<j){temp=A[i];(2);(3);}}while(i<j);A[a] =A[j];A[j] =x;if(s<i-1) (4);if(j+1<t) (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)处的字名写在的对应栏内。[说明] 以下函数完成求表达式的值,请填空使之完成此功能。float sum ( float x ){ float s=0.0;int sign = 1;(1);for(inti=1;(2); i+ +){t=t*x;s=s+(3);sign = - sign;(4);}

考题 阅读以下函数说明和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);}

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

考题 ()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]有一个一维数组cj,内放20个学生成绩,求平均成绩。函数ave用来求20个学生的平均成绩。[C语言函数]float ave(float a[20]){ int i;float aver,sum= (1) ;for(i=1;i20;i++) sum= (2) ;aver= (3) ;return( (4) );}main(){ float cj[20],aver;int i;printf(“input 20 cj:\n”);for(i=0;i20;i++) scanf(“%f”,cj[i]);printf(“\n”);aver= (5) ;printf(“average cj is %6.2f”,aver);}

考题 ()阅读下列说明和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?所示的类图。