首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include <iostream> using namespace std; class Stack { public: Stack(unsigned n= 10):size(n) {rep_=ew
有如下程序: #include <iostream> using namespace std; class Stack { public: Stack(unsigned n= 10):size(n) {rep_=ew
admin
2013-02-27
26
问题
有如下程序: #include <iostream> using namespace std; class Stack { public: Stack(unsigned n= 10):size(n) {rep_=ew int[size]; top=0;} Stack(Stack& s):size(s.size) { rep_=new int[size]; for(int i=0;i<size;i++) rep_
=s.rep_
; top=s.top; } ~Stack() {delete[]rep_;} void push(int a) {rep_[top]=a; top++;} int pop() {--top;return rep_[top];} bool isEmpty() const {return top==0;} private: int *rep_; unsigned size,top; }; int main() { Stack s1; for(int i= 1;i<5 ;i++) s1. push(i); Stack s2(s1); for(i= 1 ;i<3;i++) cout<<s2.pop()<<’,’; s2.push(6); si.push(7); while(!s2.isEmpty()) cout<<s2.pop()<<’,’; return 0; }执行上面程序的输出是______ 。
选项
A、4,3,2,1,
B、4,3,6,7,2,1,
C、4,3,6,2,1,
D、1,2,3,4,
答案
4
解析
栈是“先进后出”的数据结构。
转载请注明原文地址:https://kaotiyun.com/show/P4Vp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<stdio.h>main(){inta=5,b=1,t;t=(a<<2)∣b;printf("%d\n",t);}程序运行后的输出结果是()。
若有以下定义:intx[10],*pt=x;则对x数组元素的正确引用是()。
以下定义语句中正确的是()。
设数据元素的集合D={1,2,3,4,5},则满足下列关系R的数据结构中为线性结构的是()。
以下数组定义中错误的是()。
对于以下函数声明 voidfun(intarray[4],int*ptr);以下叙述中正确的是()。
重载的关系运算符和逻辑运算符的返回类型应当是【】。
在C++中,数据封装要解决的问题是()。
为解决在多重继承环境中因公共基类带来的【】问题,C++语言提供了虚基类机制。
在结构化设计方法中,数据流图表达了问题中的数据流与加工之间的关系,并且,每一个【 】实际上对应一个处理模块。
随机试题
下列哪种激素的分泌不受腺垂体的控制
肝颈静脉回流征不出现于下列哪种疾病()
充抵保证金的有价证券,在计算保证金金额时应当以证券市值按一定折算率进行折算,其中折算率最高的是()。
公共物品的效率由()组成。
边防工作可以分为()。
马克思主义哲学认为,社会进步具有曲折性和___________。社会的进步是通过_____________实现的。因为____________对于旧势力和反动阶级来说,就意味着被推翻、被打倒、被抛出历史舞台。正因为如此,他们的抵御和反抗是顽固而持久的。这
下列有关数据库的描述,正确的是()。
Whatwastheresearchabout?
Thegameendedafewhoursearly,leavingplayersand______unsatisfied.
Duringsleep,thefatigue(疲劳)ofthebody【S1】______andrecuperation(恢复)begins.Thetiredmindgathersnewenergy.Onceawake,the
最新回复
(
0
)