高中信息技术 / 教科版(2019) / 选修1 数据与数据结构 / 第5单元 栈及其应用 / 5.1 栈结构及其实现 / 编号:24179734

教科版(2019)选修一5.1栈结构及其实现同步训练(含解析)

日期:2025-11-04 科目:高中信息技术 类型:试卷 来源:二一教育课件站
关键词:top,程序,len,while,队列,如下
预览图 5
高中信息技术 高中信息技术
教科版(2019)选修一5.1栈结构及其实现同步训练 学校:_____姓名:_____班级:_____考号:_____ 一、选择题 1.有如下Python程序段: import random a=['A','B','#','#','C','D','#'] stk=[0]*len(a);top=-l for i in range(len(a)): op=random. randint(0,1) # 随机生成0或1 if op= =l and a[i]!='#": top+=l;stk[top]=a[i] a[i]='#' elif op= =0 and top!=-1 and a[i]= ='#': a[i]=stk[top];top-=l 执行该程序段后,a的值不可能的是( ) A.['A','B','#','#','C','D','#'] B.['#','#','#','#','#','#','#'] C.['#','B','#','#','C';'D','A'] D.['#','#','A','B','C','D','#'] 2.用栈的数据结构编写进制转换中的“除二取余法”的程序段如下: st=[-1]*100 top=-1 n=int(input("请输入一个十进制数: ")) while n>0: while top!=-1: print(st[top],end="") top-=1 方框处的代码由以下四部分组成: ①n=n//2 ②top+=1 ③x=n%2 ④st[top]=x 下列选项中,代码顺序正确的是( ) A.③④②① B.③①②④ C.①②③④ D.①③④② 3.栈s的最大长度为3,初始为空,经过一系列入栈、出栈操作,若元素入栈的顺序是a,b,c,d,e,f,则可能的出栈序列为( ) A.f,e,d,c,b,a B.c,b,a,f,e,d C.c,a,b,d,e,f D.c,e,d,b,a,f 4.下列有关栈和队列说法,正确的是(  ) A.栈的特点是先进先出,队列的特点是先进后出 B.栈只允在一端进行插入,在另一端进行删除 C.队列限定仅能在一端进行插入和删除操作 D.栈和队列均为操作受限的线性表 5.有如下 Python 程序段: s = input('请输入一串小写字母') head = 0; tail = 0; top = -1 s1 = [""]*((len(s)+1)//2) s2 = [""]*(len(s)//2) for i in range(len(s)): if i % 2 == 0: s1[tail] = s[i] tail += 1 else: top += 1 s2[top] = s[i] x = "" while head < tail and top > -1: x = s1[head] + x head += 1 x = x + s2[top] top -= 1 print(x) 执行该程序段,输入字符串“abcdefg”,则输出的结果是( ) A.acegbdf B.acegfdb C.gecafdb D.ecafdb 6.有如下Python程序段: import random lst=['A','B','C','D'] st=[0]*len(lst) i,top=0,-1 while i0: for i in range(2): start=(start+1)%len(wz) qu[t]=wz[start] t=t+1 wz.pop(start) mm="" while h

~~ 已预览到文档结尾了 ~~