题目
第1题
第2题
第3题
●试题二
阅读以下说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
函数MultibaseOutput(long n,int B)的功能是:将一个无符号十进制整数n转换成B(2≤B≤16)进制数并输出。该函数先将转换过程中得到的各位数字入栈,转换结束后再把B进制数从栈中输出。有关栈操作的诸函数功能见相应函数中的注释。C代码中的符号常量及栈的类型定义如下:
#define MAXSIZE 32
typedef struct{
int *elem;/*栈的存储区*/
int max; /*栈的容量,即栈中最多能存放的元素个数*/
int top;/*栈顶指针*/
}Stack;
【代码】
int InitStack(Stack *S,int n)/*创建容量为n的空栈*/
{S->elem=(int*)malloc(n *sizeof(int));
if(S->elem==NULL)return-1;
S->max=n; (1) =0;return 0;
}
int Push (Stack *s,int item)/*将整数item压入栈顶*/
{if(S->top==S->max){printf(″Stack is full!\n″);return-1;}
(2) =item;return 0;
}
int StackEmpty(Stack S){return(! S.top)?1∶0;}/*判断栈是否为空*/
int Pop(Stack *S)/*栈顶元素出栈*/
{if(! S->top){printf(″Pop an empty stack!\n″);return -1;}
return (3) ;
}
void MultibaseOutput(long n,int B)
{int m;Stack S;
if(InitStack(&S,MAXSIZE)){printf(″Failure!\n″);return;}
do {
if(Push(&S, (4) )){printf(″Failure!\n″);return;}
n= (5) ;
}while(n !=0);
while(! StackEmpty(S)){/*输出B进制的数*/
m=Pop(& S);
if(m<10)printf(″%d″,m);/*小于10,输出数字*/
else printf(″%c″,m+55);/*大于或等于10,输出相应的字符*/
}
printf(″\n″);
}
第4题
阅读以下说明和C程序代码,将应填入______处的语句写在答题纸的对应栏内。
[说明]
函数MultibaseOutput(long n,int B)的功能是:将一个无符号十进制整数n转换成 B(2≤B≤16)进制数并输出。该函数先将转换过程中得到的各位数字入栈,转换结束后再把B进制数从栈中输出。有关栈操作的诸函数功能见相应函数中的注释。C代码中的符号常量及栈的类型定义如下:
define MAXSIZE 32
typedef struct{
int * elem; /* 栈的存储区 */
int max; /* 栈的容量,即栈中最多能存放的元素个数 */
int top; /* 栈顶指针 */
}Stack;
[C代码]
int InitStack(Stack * S,int n) / * 创建容量为n的空栈 */
{ S->elem=(int *)malloc(n * sizeof(int));
if(S->elem==NULL)return-1;
S->max=n; (1)=O;return 0;
}
int Push(Stack * S,int item) / * 将整数item压入栈顶 * /
{ if(S->top==S->max){ printf(“Stack is full! \n”);return-1;}
(2)=item;return 0;
}
int StackEmpty(StackS) {return (! S.top)? 1:0;} / * 判断栈是否为空 * /
int Pop(Stack *S ) / * 栈顶元素出栈 * /
{ if(! S->top){printf(“Pop an empty stack! \n”);return-1;}
return (3);
}
void MultibaseOutput(long n,int B)
{ int m;StackS;
if (InitStack(&S,MAXSIZE)){printf(“Failure! \n”);return;}
do {
if(Push(&S, (4) )){printf(“Failure! \n”);return;}
n=(5);
}while(n!=0);
while(! StackEmpty(S)){ / * 输出B进制的数 * /
m=Pop(&S);
if(m<10)printf(“%d”,m); / * 小于10,输出数字 * /
else printf(“%c”,m+55); / * 大于或等于10,输出相应的字符 * /
}
printf(“\n”);
}
第5题
试题四
阅读以下说明和C代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
[说明]
函数MultibaseOutput(long n, int B)的功能是:将一个无符号十进制整数n转换成B(2≤B≤16)进制数并输出。该函数先将转换过程中得到的各位数字入栈,转换结束后再把B进制数从栈中输出。有关栈操作的诸函数功能见相应函数中的注释。C代码中的符号常量及栈的类型定义如下:
#define MAXSIZE 32
typedef struct {
int *elem; /* 栈的存储区 */
int max; /* 栈的容量,即栈中最多能存放的元素个数 */
int top; /* 栈顶指针 */
}Stack;
[C代码]
int InitStack(Stack *S, int n) /* 创建容量为n的空栈 */
{ S->elem = (int *)malloc(n * sizeof(int));
if(S->elem == NULL) return -1;
S->max = n; (1) = 0 ; return 0;
}
int Push(Stack *S, int item) /* 将整数item压入栈顶 */
{ if(S->top == S->max){ printf("Stack is full!\n"); return -1;}
(2) = item ; return 0;
}
int StackEmpty(Stack S) { return (!S.top) ? 1 : 0; } /* 判断栈是否为空 */
int Pop(Stack *S) /* 栈顶元素出栈 */
{ if(!S->top) { printf("Pop an empty stack!\n"); return -1;}
return (3) ;
}
void MultibaseOutput(long n, int B)
{ int m; Stack S;
if (InitStack(&S, MAXSIZE)) {printf("Failure!\n"); return;}
do {
if (Push(&S, (4) )) {printf("Failure!\n"); return;}
n = (5) ;
}while(n != 0);
while(!StackEmpty(S)) { /* 输出B进制的数 */
m = Pop(&S);
if(m < 10) printf("%d", m); /* 小于10,输出数字 */
else printf("%c", m + 55); /* 大于或等于10,输出相应的字符 */
}
printf("\n");
}
第6题
将一个非负十进制整数转换成八进制数,使用非递归算法实现。
算法分析:十进制转换成八进制的过程是将十进制整数除8得余数,直到商是0为止,然后倒排余数。为了得到倒排的余数,可以利用栈来实现,每次运算后将余数压入栈中,直到商为0,将栈中数据输出即是。使用顺序栈,将顺序栈的定义及其基本操作的实现写在头文件“seqstack.h”中。
第7题
以下应用中,必须采用栈结构的是______。
A.使一个整数序列逆转
B.递归函数的调用和返回
C.申请和释放单链表中的节点
D.装入和卸载可执行程序
第8题
● 以下应用中,必须采用栈结构的是 (41) 。
(41)
A. 使一个整数序列逆转
B. 递归函数的调用和返回
C. 申请和释放单链表中的结点
D. 装入和卸载可执行程序
第9题
1.当人、出栈次序为Push(1),Pop(),Push(2),Push(3),Pop(),Push(4),Pop(),出栈的数字序列为何?(这里Push(i)表示i进栈,Pop()表示出栈)(26)
2.能否得到出栈序列1、4、2、3和1、4、3、2?答案为(27)。
3.请分析研究1、2、3、4的24种排列中,(28)序列是可以通过相应的入、出栈操作得到的。
A.1,3,4
B.1,4,2,3
C.1,4,3
D.3,4,1
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!