首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。 [说明] 以下程序的功能是实现堆栈的一些基本操作。堆栈类stack共有三个成员函数:empty判断堆栈是否为空;push进行人栈操作;pop进行出栈操作。 [C++程序] #include
阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。 [说明] 以下程序的功能是实现堆栈的一些基本操作。堆栈类stack共有三个成员函数:empty判断堆栈是否为空;push进行人栈操作;pop进行出栈操作。 [C++程序] #include
admin
2009-02-15
15
问题
阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。
[说明]
以下程序的功能是实现堆栈的一些基本操作。堆栈类stack共有三个成员函数:empty判断堆栈是否为空;push进行人栈操作;pop进行出栈操作。
[C++程序]
#include "stdafx. h"
#include <iostream, h>
eonst int maxsize = 6;
class stack {
float data[ maxsize];
int top;
public:
stuck(void);
~ stack(void);
bool empty(void);
void push(float a);
float pop(void);
};
stack: :stack(void)
{ top =0;
cout < < "stack initialized." < < endl;
}
stack:: ~stack(void) {
cout < <" stack destoryed." < < endl;
bool stack:: empty (void) {
return (1);
void stack: :push(float a)
if(top= =maxsize) {
cout < < "Stack is full!" < < endl;
return;
data[top] =a;
(2);
}
float stack:: pop (void)
{ if((3)){
cout< < "Stack is undcrflow !" < < endl;
return 0;
(4);
return (5);
}
void main( )
{ stack s;
coat < < "now push the data:";
for(inti=l;i< =maxsize;i+ +) {
cout< <i< <" ";
s. push(i);
}
coat < < endl;
cout< < "now pop the data:";
for(i = 1 ;i < = maxsize ;i + + )
cout< <s. pop()< <" ";
}
选项
答案
(1)top==0? true:false (2)top++(或者top =top+1)(3)top==0 (4)top--(或者top =top-1) (5)data[top]
解析
(1)判断堆栈是否为空的条件是top为0,而且本函数的返回值为布尔类型,故此处应该填写top==0? true:false;
(2)数据入栈后,栈顶指针要向上移动一个单元;
(3)top为0说明堆栈已经空了,此处if语句返回堆栈为空的提示;
(4)先将栈顶指针往下移动一个单元,才可以指向要出栈的数据;
(5)本行代码的功能是返回要出栈的数据。
转载请注明原文地址:https://kaotiyun.com/show/HEjZ777K
本试题收录于:
程序员下午应用技术考试题库软考初级分类
0
程序员下午应用技术考试
软考初级
相关试题推荐
在Excel的A1单元格中输入函数“=LEFT(“信息处理技术员”,2)”,按回车键后,A1单元格中的值为()。
新建一个Word文档,编辑结束后,执行“文件”菜单中的“保存”命令,则______。
字符串编辑有3种基本操作:在指定位置插入一个字符、在指定位置删除一个字符、在指定位置用另一个字符替换原来的字符。将字符串ABCDE,编辑成ECDFE,至少需要执行(6)次基本操作。
在Excel2007中,设单元格A1中的值为-1,B1中的值为1,A2中的值为0,B2中的值为1,若在C1单元格中输入函数“=IF(AND(A1>0,B1>0),A2,B2)”,按回车键后,C1单元格中的值为______。
Word定时自动保存功能可以()。
面向社会服务的信息系统突发安全事件时所采取的技术措施中一般不包括(62)________________。
以下关于Word2010图形和图片的叙述中,不正确的是()。
在Windows7中,磁盘文件类型可以根据______来识别。
下列关于Windows7屏幕保护程序的叙述中,不正确的是__________。
在Excel的A1单元格中输入函数“=ROUND(3.1415,2)”,则A1单元格中显示的值为(57)。
随机试题
Adamisfullyawarethat______,hisfactorywillhavetoclosedowninlessthanayear.
试从教学过程的某一规律出发,评析“教帅中心论”与“儿童中心论”。
有关解剖学方位的描述,错误的是
关于联合体投标,下列表述中正确的是()。
商业银行接受客户委托进行投资操作和资产管理等个人理财业务,应与客户签订合同,并对相关合同和各类授权文件至少()重新确认一次。
甲公司于2016年1月1日购入A公司同日发行的3年期公司债券,作为持有至到期投资核算。购买该债券共支付价款10560.42万元,债券面值10000万元,每年12月31日付息一次,到期还本,票面年利率6%,实际年利率4%。采用实际利率法摊销,则甲公司20
下列各项技术分析方法中,由波特提出的方法是()。
从所给的四个选项中,选择最合适的一个填入问号处,使之呈现一定的规律性:
一些美国心理学家得出结论认为:父母对儿童采取的行为一种是总表示接受,一种是总表示拒绝。心理学家得出这样的结论是因为研究者高度同意母亲的行为能表明这些父母的态度。上面所提及的心理学家所得的结论依据于这样的假设,即:
Atthebeginningofthetwentiethcentury,NorthAmericansocietyheld,asanideal,theNuclearFamily.Thispresumablyperfect
最新回复
(
0
)