标题:帮小弟调试一下一个小栈的程序
取消只看楼主
heliujin
Rank: 2
等 级:论坛游民
帖 子:249
专家分:14
注 册:2006-3-14
结帖率:100%
 问题点数:0 回复次数:1 
帮小弟调试一下一个小栈的程序

这个小程序有问题 请大家帮忙指出错误在哪里?谢谢大家了
#include<iostream.h>
#define MAX 100

class stack
{
public:
stack(){}

stack(int s)
{
top=0;
bottom=0;
size=s;
}

int pop();
void push(int i);
bool empty();
void disp();
private:
int top;
int bottom;
int size;
int a[MAX];
};

stack::void push(int i)
{
if(top-bottom<=size)
{
a[top]=i;
}
top=top+1;
}

stack::int pop()
{
if(--top>=bottom)
{
return a[bottom];
}
else
cout<<"this is a empty stack"<<endl;
}

stack::bool empty()
{
if(top==bottom)
return true;
else
return false;
}

stack::void disp()
{
for(int i=0;i<top;i++)
{
cout<<a[i]<<" ";
}
}

int main()
{
stack m(4);
m.push(2);
m.push(3);
m.push(4);
m.push(5);
m.disp();
return 0;
}


搜索更多相关主题的帖子: 调试 
2006-06-23 08:21
heliujin
Rank: 2
等 级:论坛游民
帖 子:249
专家分:14
注 册:2006-3-14
得分:0 
小弟谢谢大家的指教的 以后这样的问题我会注意的
2006-06-25 07:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-74218-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.280798 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved