///////////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();
}
}
请调试一下,,,好象是划红线的部分不对......找不出原因.....