首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。 [说明] 以下程序的功能是实现堆栈的一些基本操作。堆栈类stack共有三个成员函数:empty判断堆栈是否为空;push进行人栈操作;pop进行出栈操作。 [C++程序] #include
阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。 [说明] 以下程序的功能是实现堆栈的一些基本操作。堆栈类stack共有三个成员函数:empty判断堆栈是否为空;push进行人栈操作;pop进行出栈操作。 [C++程序] #include
admin
2009-02-15
17
问题
阅读以下说明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://jikaoti.com/ti/SvW7FFFM
本试题收录于:
程序员下午应用技术考试题库软考初级分类
0
程序员下午应用技术考试
软考初级
相关试题推荐
在Excel中,若A1单元格的值为5,在B1单元格输入函数“=A1-10”,则B1单元格的值为______。
某商场的部门和商品两个实体之间的关系如下图所示。假设每个部门负责销售若干种商品,每种商品只能由一个部门负责销售,那么部门和商品之间存在着(14)的联系。
以下关于信息存储的叙述中,不正确的是(66)。
在Word2007中,字符样式应用于__________。
台式计算机在设定的等待时间内,如果用户没有进行任何操作,将启动________________。
数据________________是将数据以图形图像形式表示,并利用数据分析工具发现其中未知信息的处理过程。
某地区去年粮食产量资料如下表:根据该表可以推算出,该地区去年薯类的产量为()万吨。
下面关于幻灯片打印的叙述中,正确的是______。
在浏览网页时,当鼠标指针移至某些文字或某些图片时,会出现手形状,通常是由于网页在这个地方做了(17)。
在统计学中,用来衡量一个样本中各个数据波动大小的量是______。
随机试题
泰勒的科学管理理论的影响。
关于试带法胆红素测定的叙述,不正确的是
( )是组织在其工作中直接形成的有保存价值的历史记录。
以下哪种状况会导致安全边际下降
2000年,我国国内生产总值超过了原定较1980年翻两番的目标,这种增长主要是依赖资源的高投入、高消耗来实现的。到2020年实现国内生产总值再翻两番,是我国实现全面建设小康社会的奋斗目标。我国单位GDP消耗的资源能源数量远高于发达国家,也高于印度
神话是远古人民表现的对自然及文化现象的理解与想象的故事。神话并非现实生活的科学反映,而是由于远古时代,人类开始思考与探索自然并结合自己的想象力所产生的。根据上述定义,下列不属于神话的是()。
根据侵权责任法,因紧急避险造成损害,如果危险是由自然原因引起的,紧急避险人的责任如何?()
毛泽东提出要造成一个又有集中又有民主,又有纪律义有自由,又有统一意志、又有个人心情舒畅、生动活泼,那样一种政治局面(通称“六又”政治局面)的思想是在()
TheFrencharethemastersof"grandsprojets".(46)Theyhavethecruelnes,nationalprideandwillingnesstospendthatarenee
U.S.BlacksHard-hitbyCancerDeathratesforcancerarefallingforallAmericans,butblackAmericansarestillmorelikelyt
最新回复
(
0
)