●试题二
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
函数print(BinTreeNode*t;DateType &x)的功能是在二叉树中查找值为x的结点,并打印该结点所有祖先结点。在此算法中,假设值为x的结点不多于一个。此算法采用后序的非递归遍历形式。因为退栈时需要区分右子树。函数中使用栈ST保存结点指针ptr以及标志tag,Top是栈顶指针。
【函数】
void print(BinTreeNode*t;DateType &x){
stack ST;int i,top;top=0;∥置空栈
while(t!=NULL &&t->data!=x‖top!=0)
{while(t!=NULL && t->data!=x)
{
∥寻找值为x的结点
(1) ;
ST[top].ptr=t;
ST[top].tag=0;
(2) ;
}
if(t!=Null && t->data==x){∥找到值为x的结点
for(i=1; (3) ;i++)
printf("%d",ST[top].ptr->data);}
else{
while( (4) )
top--;
if(top>0)
{
ST[top].tag=1;
(5) ;
}
}
}
第1题:
●试题二
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
该程序运行后,输出下面的数字金字塔
【程序】
include<stdio.h>
main ()
{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");
}
}
第2题:
()阅读下列说明和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); }
第3题:
第4题:
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第5题:
第6题: