C++ 堆栈

classseqstack//头文件{public:int*data;inttop;intmaxsize;public:seqstack(intmx){top=-1;ma... class seqstack//头文件
{
public:
int *data;
int top;
int maxsize;
public:
seqstack(int mx)
{
top=-1;
maxsize=mx;
data=new int[maxsize];
}
bool isempty();//是否为空
void push(int value);//入栈
void pop();//出栈
int gettop();//取顶点元素
bool isfull();//是否已满
};

#include"iostream.h"
#include"stdlib.h"
bool seqstack::isempty()
{
if(top==-1)
return 1;
return 0;
}
bool seqstack::isfull()
{
if(top==maxsize-1)
return 1;
return 0;
}
void seqstack::push(int value)
{
if(seqstack::isfull())
{
cout<<"the stack is full"<<endl;
abort();
}
top++;
data[top]=value;
}
void seqstack::pop()
{
if(seqstack::isempty())
{
cout<<"the stack is empty"<<endl;
abort();
}
top--;
}
int seqstack::gettop()
{
if(isempty())
{
cout<<"the stack is full"<<endl;
abort();
}
int value=data[top];
return value;
}

#include"iostream.h"
#include"seqstack.h"
void main()
{
int mx,n;
int value;
cout<<"max size of the stack"<<endl;
cin>>mx;
seqstack s(mx);
cout<<s.isempty();
cout<<"push how many value"<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"push value";
cin>>value;
s.push(value);
}
cout<<s.gettop()<<endl;
s.pop();
s.pop();
s.gettop();
s.pop();
s.pop();
s.pop();
s.pop();
cin>>value;
s.push(value);
}
展开
 我来答
鸟人和天使
2008-03-31 · TA获得超过113个赞
知道答主
回答量:240
采纳率:0%
帮助的人:0
展开全部
帮你单步调了下,程序没什么问题只是其中的头文件放开头的地方!另外不明白你最后的那几句什么意思!还有个建议,你这么多函数里都用到了判断栈是不是空的,最好把同样的语句封装到一个函数内,然后让其他函数调用它!!
attackover
2008-03-31 · 超过75用户采纳过TA的回答
知道小有建树答主
回答量:269
采纳率:0%
帮助的人:232万
展开全部
你想说什么?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式