按书建栈,编译没通过
我按书上输了一个栈实例,但通不过编译,请教高手:#include<iostream>
#include<string>
#include<vector>
using namespace std;
class istack{
public:
iStack( int capacity )//这里就通不过了
: _stack( capacity ), _top( 0 ) {}
bool pop(int &value);
bool push(int value);
bool full();
bool empty();
void display();
int size();
private:
int _top;
vector<int>_stack;
};
inline bool istack::size(){return _top;};
inline bool istack::empty()
{return _top?false:true;}
inline bool istack:full()
{return _top<_stack.size()-1?false:true;}
bool istack::pop(int &top_value)
{
if(empty())
return false;
top_value=stack[--_top];
cout<<"istack:pop():"<<top_value<<endl;
return true;
}
bool istack::push(value)
{
cout<<"istack::push()("<<value<<")\n";
if(full())
return false;
_stack[_top++]=value;
return true;
}
void istack::display()
{
if(!size())
{cout<<"(0)\n";return;}
cout<<"("<<size()<<")(bot:";
for(int ix=0;ix<_top;++ix)
cout<<_stack[ix]<<" ";
cout<<":top)\n";
}
int main()
{
istack stack(32);
stack.display();
for(int ix=1;ix<51;++ix)
{
if(ix%2==0)stack.push(ix);
if(ix%5==0)stack.display();
if(ix%10==0){
int dummy;
stack.pop(dummy);stack.pop(dummy);
stack.display();
}
}
}