碰到access violation
#include <iostream.h>
typedef struct
{
int* array;
int sp;
int size;
}StackStruct;
class Queue {
public:
void Init(StackStruct *s, int size);
void cleanUp();
int isEmpty(StackStruct *s);
int isFull(StackStruct *s);
void push(int item);
int pop(StackStruct *s);
public:
StackStruct *s;
};
void Queue::Init(StackStruct *s, int size)
{
s->array = new int[size];
s->size = size;
s->sp = 0;
}
void Queue::cleanUp()
{
delete s->array;
}
int Queue::isEmpty(StackStruct *s)
{
return s->sp == 0 ? 1 : 0;
}
int Queue::isFull(StackStruct *s)
{
return s->sp == s->size ? 1 : 0;
}
void Queue::push(int item)
{
if(!isFull(s)) s->array[s->sp++] = item;
}
int Queue::pop(StackStruct *s)
{
if(isEmpty(s))
return 0;
else
return s->array[--s->sp];
}
void main()
{
Queue queue;
StackStruct *stack =queue.s;
queue.Init(stack, 15);
for(int i=0; i < 25; i++)
queue.push(i);
while(!queue.isEmpty(stack))
cout<<queue.pop(stack)<<" ";
cout<<endl;
}
执行到s->array = new int[size];语句时出错,为access violation
请高手指点.