提示debug assertion failed,帮忙看看代码问题在哪里。有谢

// 队列模拟栈.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
using namespace std;
template
struct QueueNode
{
QueueNode*link;
T data;
};
template
class TheStack
{
private:
QueueNodefront;
QueueNode*rear;
public:
TheStack(){ front = rear = NULL; }
~TheStack();
bool IsEmpty()const
{
return((front) ? false : true);
}
int getSize()const;
T first()const;
T last()const;
TheStackAdd(const T&x);
TheStackDelete(T&x);
};
template
TheStack::~TheStack()
{
QueueNode*next;
while (front!=NULL)
{
next = front;
front = front->link;
delete next;
}
};
template
int TheStack::getSize()const
{
QueueNode*p = front;
int k = 0;
while (p != NULL)
{
p = p->link;
k++;
}
return k;
};
template
T TheStack::first()const
{
if (IsEmpty())
{
cout << "没有元素了。";
}
return front->data;
};
template
T TheStack::last()const
{
if (IsEmpty())
{
cout << "没有元素了。";
}
return rear->data;
};
template
TheStack TheStack::Add(const T&x)
{
QueueNode*p = new QueueNode;
p->data = x;
p->link = 0;
if (front){ rear->link = p; }
else
front = p;
rear = p;
return *this;
};
template
TheStack TheStack::Delete(T&x)
{
if (IsEmpty())
{
cerr << "It's empty queue";
}
else
x = front->data;
QueueNode*p = front;
front = front->link;
delete p;
return*this;
};
int _tmain(int argc, _TCHAR
argv[])
{
TheStackp1, p2;
int m, n, z, y;
cout << "你想压入几个数字?" << endl;
cin >> y;
int*a = new int[y];
cout << "请输入这一串数字并同时会压入p1中:" << endl;
for (int i = 0; i < y; i++)
{
int m = a[i];
p1.Add(m);
}
delete[]a;
n = p1.getSize();
cout << "请输入一串数到q1队列中:" << endl;
while (!p1.IsEmpty() || !p2.IsEmpty())
{
while (p1.first() == p1.last() && p2.IsEmpty() && !p1.IsEmpty())
{
m = p1.first();
p2.Add(m);
p1.Delete(m);
}
z = p1.first();
cout << z << endl;
p1.Delete(z);
while (p2.first() == p2.last() && p1.IsEmpty() && !p2.IsEmpty())
{
m = p2.first();
p1.Add(m);
p2.Delete(m);
}
z = p2.first();
cout << z << endl;
p2.Delete(z);
}
return 0;
}

为了5分默默的赞一个。楼主别怒