打印杨辉3角出现的问题,求改错
#include<assert.h>#include <iostream.h>
template <class T>
class SeqQueue //队列类定义
{ private:
int rear, front; //队尾与队头指针
T *elements; //队列存放数组
int maxSize;
public:
SeqQueue(int sz = 10); //构造函数
~SeqQueue() { delete[ ] elements; } //析构函数
bool EnQueue(T x); //新元素进队列
bool DeQueue(T & x); //退出队头元素
bool getFront(T& x) const ; //取队头元素值
void makeEmpty() { front = rear = 0; }
bool IsEmpty() const
{ return (front == rear)?true:false; }
bool IsFull() const
{ return ((rear+1) % maxSize == front )?true:false; }
int getSize() const
{ return (rear-front+maxSize) % maxSize; }
};
template <class T>
SeqQueue<T>::SeqQueue(int sz) //构造函数
{ front=rear=0;
maxSize=sz;
elements = new T[maxSize];
assert ( elements != NULL );
};
template <class T>
bool SeqQueue<T>::EnQueue(T x)
//若队列不满,则将元素x插入到该队列的队尾,否则出错处理
{ if (IsFull() == true) return false; //队列慢则插入失败,返回
elements[rear] = x; //按照队尾指针指示位置插入
rear = (rear+1) % maxSize; //队尾指针加1
return true;
};
template <class T>
bool SeqQueue<T>::DeQueue(T & x)
//若队列不空则函数退掉一个队头元素并返回true,否则返回false。
{ if (IsEmpty() == true) return false;
x = elements[front]; //先取队头
front = (front+1) % maxSize; //再队头指针加1
return true;
};
template <class T>
bool SeqQueue<T>::getFront(T& x) const
//若队列不空则函数返回该队列队头元素的值
{ if (IsEmpty() == true) return false; //队列空
x = elements[front]; //返回队头元素
return true;
};
void main ()
{ int n;
cout<<" 输入 "<<endl;
SeqQueue<int>q(n+2); //队列初始化
q.MakeEmpty (); q.EnQueue (1); q.EnQueue (1);
int t,s = 0;
for ( int i = 1; i <= n; i++ ) //逐行计算
{ cout << endl;
q.EnQueue (0);
for ( int j = 1; j <= i+2; j++ ) //下一行
{ q.DeQueue (t); q.EnQueue ( s + t ); s = t;
if ( j != i+2 ) cout << s << ' ';
}
}
}