两个栈模拟一人队列,代码错在哪里?在主函数中加入代码就会出错.为什么?
#include <iostream>
using namespace std;
template <class T>
class Stack
{
//private:
public:
T * st;
int top; //顶栈的位置
int mSize; //最大的空间
void push(const T item)
{
if(top==mSize-1)
{
cout<<"1 满 \n";
}
else
{
st[++top]=item;
}
}
int pop(T& item)
{
if(top==-1)
{
cout<<"空,\n";
return 0;
}
else
{
item=st[top--];
return item;
}
}
};
template <class T>
class S_Queue
{
private:
Stack<int> A;
Stack<int> B;
public:
void enQueue(T item)
{
A.push(item);
while(!isempty(A))
{
B.push(A.pop(item));
}
}
void deQueue(T &item)
{
B.pop(item);
while(!isempty(B))
{
A.push(B.pop(item));
}
}
int isempty(Stack<T> S)
{
if(S.top==-1)return 1;
else return 0;
}
};
int main()
{
Stack<int> A;
A.push(90);A.push(11);A.push(23);A.push(67);A.push(9);A.push(34);
S_Queue<int> S;
}
以上是我写的,用两个栈模拟一个队列.
可是大主函数中加入以下的码时就会出错,为什么??
// S.enQueue(46);
// int i;
//S.enQueue(i);
//return 0;