用循环队列写杨辉三角形

用循环队列写杨辉三角形
#include 
using namespace std;
const int MaxSize=100;

template 
class SqQueueClass				//非循环队队列类模板
{
	T *data;  					//存放队中元素
	int front, rear;			//队头和队尾指针
public:
	SqQueueClass();				//构造函数
	~SqQueueClass();			//析构函数
	bool QueueEmpty();			//判断队列是否为空
	bool enQueue(T e);			//进队列算法
	bool deQueue(T &e);			//出队列算法
};

template 
SqQueueClass::SqQueueClass()		//构造函数
{
	data=new T[MaxSize];			//为data分配空间
	front=rear=-1;					//队头队尾指针置初值
}
template 
SqQueueClass::~SqQueueClass()	//析构函数
{
	delete [] data;
}
//----------非循环队基本运算算法------------------------
template 
bool SqQueueClass::QueueEmpty()	//判断队列是否为空
{
	return (front==rear);
}
template 
bool SqQueueClass::enQueue(T e)	//进队列算法
{
	if (rear==MaxSize-1)			//队满上溢出
		return false;
	rear++;
	data[rear]=e;
	return true;
}
template 
bool SqQueueClass::deQueue(T &e)	//出队列算法
{
	if (front==rear)				//队空下溢出
		return false;
	front++;
	e=data[front];
	return true;
}
void yanghui(int n)
{
    SqQueueClassq;
    int i=1,j,s,k,t,u;
    s=k=0;
    q.enQueue(i);
    q.enQueue(i);
    for(int i=1;i<=n;i++)
    {
        cout<>n;
    yanghui(n);
	return 0;
}

你可能感兴趣的:(数据结构)