| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 474 人关注过本帖
标题:帮小弟调试一下一个小栈的程序
只看楼主 加入收藏
heliujin
Rank: 2
等 级:论坛游民
帖 子:249
专家分:14
注 册:2006-3-14
结帖率:100%
收藏
 问题点数:0 回复次数:5 
帮小弟调试一下一个小栈的程序

这个小程序有问题 请大家帮忙指出错误在哪里?谢谢大家了
#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
aogun
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:638
专家分:0
注 册:2006-4-5
收藏
得分:0 
居然没人回??我来吧,你犯了基本的语法错误,方法格式写错了
类似stack::bool empty()这种是错误的
应该是bool stack::empty()

世界上总共有 10 种人,一种懂得什么是二进制 ,一种不懂。
2006-06-23 10:21
song4
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:38
帖 子:1533
专家分:4
注 册:2006-3-25
收藏
得分:0 
大早上的
谁上班呀
就你喜欢早练

嵌入式 ARM 单片机 驱动 RT操作系统 J2ME LINUX  Symbian C C++ 数据结构 JAVA Oracle 设计模式 软件工程 JSP
2006-06-23 15:37
aogun
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:638
专家分:0
注 册:2006-4-5
收藏
得分:0 
当学生真好,我决定明早睡到11点

世界上总共有 10 种人,一种懂得什么是二进制 ,一种不懂。
2006-06-23 17:42
duanshao
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-6-8
收藏
得分:0 

#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];
};

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

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

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

void stack::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-24 21:57
heliujin
Rank: 2
等 级:论坛游民
帖 子:249
专家分:14
注 册:2006-3-14
收藏
得分:0 
小弟谢谢大家的指教的 以后这样的问题我会注意的
2006-06-25 07:05
快速回复:帮小弟调试一下一个小栈的程序
数据加载中...
 
   



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

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