is there have a way the stack's initial size is 0, it should still be possible to push values onto the stack.
Here is my code:
class IntStack
{
int *p;
int top;
int maxlen;
public:
IntStack();
IntStack(int);
~IntStack();
void push(int);
int pop();
void push (int a[], int array_size);
};
IntStack::IntStack(int size)
{
maxlen=size;
top=-1;
p=new int[maxlen];
}
void IntStack::push(int i)
{
if(top==maxlen-1)
{cout<<"there is full";}
top++;
p[top]=i;
}
int IntStack::pop()
{
int V;
if(top==-1)
{
cout<<"There is empty\n";
}
else
{
V=p[top];
top--;
return V;}
}
and here have some exception when i did that:
int main()
{
IntStack stack(0);
stack.push (1);
}
somebody know where is the problem, plz help me