| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 743 人关注过本帖
标题:[求助]谁能看一下这个栈的top()函数问题
只看楼主 加入收藏
love154139
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2007-5-6
收藏
 问题点数:0 回复次数:2 
[求助]谁能看一下这个栈的top()函数问题

///////////stack.h文件/////
#ifndef STACK_H_
#define STACK_H_
#include "uitily.h"

class stack
{
public:
stack();
void empty();
bool full();
errorcode pop();
int size();
errorcode push(const int &item);
errorcode top(int item);
private:
int count;
int entry[maxsize];
};


stack::stack()
{
count=0;
}

void stack::empty()
{
count=0;
}

bool stack::full()
{
if(count>=maxsize)
return false;
else
return true;
}

int stack::size()
{
return count;
}


errorcode stack::push(const int &item)
{
errorcode outcome=success;
if(count>=maxsize)
outcome=overflow;
else
{
entry[count]=item;
count++;
}
return outcome;
}

errorcode stack::top(int item)
{
int a;
errorcode outcome=success;
if(count<=0)
outcome=underflow;
else
item=entry[count-1];///这里item的值不对的.谁能解释一下
return outcome;
}

errorcode stack::pop()
{
errorcode outcome=success;
if(count==0)
outcome=underflow;
else
--count;
return outcome;
}

#endif

/////////uitily.h文件//////////
#ifndef UITILY_H_
#define UITILY_H_

const int maxsize=10;
enum errorcode{success,overflow,underflow};


#endif




////main.cpp/////////
#include "stack.h"
#include <iostream>
using namespace std;
#include "uitily.h"


void main()
{
int a;
stack s;
cout<<"请输入一个数0结束"<<endl;
cin>>a;
while(a!=0)
{
s.push(a);
cin>>a;
}
while(s.size()!=0)
{
s.top(a);
cout<<a<<" ";
s.pop();
}
}

请调试一下,,,好象是划红线的部分不对......找不出原因.....

搜索更多相关主题的帖子: stack top 函数 int count 
2007-07-03 17:06
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
errorcode stack::top(int &item) //传引用调用
{
int a;
errorcode outcome=success;
if(count<=0)
outcome=underflow;
else
item=entry[count-1];///这里item的值不对的.谁能解释一下
return outcome;
}

Fight  to win  or  die...
2007-07-03 17:21
love154139
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2007-5-6
收藏
得分:0 
可以了...谢谢楼上的哦~~~~

2007-07-03 17:26
快速回复:[求助]谁能看一下这个栈的top()函数问题
数据加载中...
 
   



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

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